#[define]Expand description
This attribute defines a function-like macro based on the template module it annotated. One can define actual modules with variations by calling the defined macro with different arguments.
§Example
ⓘ
// To define a module-defining macro that called `define_foo_mod`, and let
// the macro user to customize some functions in the module by specifying
// ways to construct variables (`BAR`), substitute attributes (along with
// extend the function signature) (`BAZ`), one can write:
#[mod_template::define(
macro_rules! define_foo_mod;
constructions(BAR -> impl crate::BarTrait),
attribute_substitutions(BAZ)),
]
mod __ {
#[__CONSTRUCT(bar as BAR)]
#[__SUBSTITUTE(BAZ)]
fn an_fn() {
bar.do_something();
}
}
// Call the defined macro to produce an actual module (named as `actual_foo`):
define_foo_mod! {
mod actual_foo;
constructions {
BAR => crate::Bar::new(),
},
attribute_substitutions {
BAZ => #[::baz::baz],
// If one want to extend the signature of the function annotated by
// `#[__SUBSTITUTE(BAZ)]`, use
// `BAZ => #[::baz::baz] (.., qux: crate::Qux),`.
},
}See mod_template::define.