[][src]Macro wonderbox::register_autoresolvable

macro_rules! register_autoresolvable {
    ($container: ident, $implementation: ty) => { ... };
    ($container: ident, $implementation: ty as $outer_type:tt <$inner_type: ty>) => { ... };
}

Primary way to register types annotated with #[autoresolvable]. This macro is syntax sugar over register_autoresolvable

Examples

use wonderbox::{autoresolvable, register_autoresolvable, Container};

trait Foo {}

#[derive(Debug, Default)]
struct FooImpl {
    stored_string: String,
}

#[autoresolvable]
impl FooImpl {
    fn new(stored_string: String) -> Self {
        Self { stored_string }
    }
}

impl Foo for FooImpl {}

let mut container = Container::new();
container.register(|_| "foo".to_string());
register_autoresolvable!(container, FooImpl as Box<dyn Foo>);

let foo = container.try_resolve::<Box<dyn Foo>>();
assert!(foo.is_some())