Attribute Macro lockjaw::builder_modules [−][src]
#[builder_modules]
Expand description
Annotates a struct that contains modules
instances to be installed in a
component
with the builder_modules
field. If a module contains fields, it cannot be
auto generated and must be explicitly provided to
COMPONENT.build()
The annotated struct will become the parameter for
COMPONENT.build()
If a module does not contain any field, it can be auto generated by lockjaw, and can be listed in
the modules
field instead.
struct StringModule {
string : String
}
#[module]
impl StringModule {
#[provides]
pub fn provide_string(&self) -> String {
self.string.clone()
}
}
#[builder_modules]
pub struct MyBuilderModules {
module : crate::StringModule,
}
#[component(builder_modules : crate::MyBuilderModules)]
pub trait MyComponent {
fn string(&self) -> String;
}
fn main() {
let component = MyComponent::build(MyBuilderModules{
module: StringModule{
string: "foo".to_owned()
}
});
assert_eq!("foo", component.string());
}
epilogue!();