blueprint
blueprint copied to clipboard
[TASK] Tangle job metadata generation
Overview
Using the type system, we can already determine all of the parameter and return types to put them in the blueprint.json.
What we can't know, though, is the description and the argument names.
Proposed Solution
Add a small proc macro to generate a struct holding the extra job metadata.
// The `tangle_job` proc macro has much more information available than the type system provides
/// My job
#[tangle_job]
fn foo(arg: TangleArg<u16>) -> TangleResult<()>;
The #[tangle_job] macro generates the following:
/// My job
fn foo(arg: TangleArg<u16>) -> TangleResult<()>;
struct FooMetadata {
name: &'static str,
description: &'static str,
params: [&'static str; 1]
}
impl FooMetadata {
fn init() -> Self {
Self {
name: "foo",
description: "My job",
params: ["arg"]
}
}
}
It does so by taking the function name and parameter names (pretty much for free), and then building the description string from the doc comments.
Then, to apply the metadata to the job, just specify it in your blueprint! macro:
blueprint! {
job: [(foo, FooMetadata::init())]
}
Meaning this only adds 2 small extra steps for defining a job:
- Putting
#[tangle_job]on your job - Specifying the metadata type in the
blueprint!macro