extern crate he_di; #[macro_use] extern crate he_di_derive; trait Foo { fn get_value(&self) -> usize; fn set_value(&mut self, _: usize); } #[derive(Component)] #[interface(Foo)] struct FooImpl { value: usize, } impl Foo for FooImpl { fn get_value(&self) -> usize { self.value } fn set_value(&mut self, val: usize) { self.value = val; } } fn main() { let mut builder = he_di::ContainerBuilder::new(); builder .register::() .as_type::() .with_named_parameter("value", 17 as usize); let mut container = builder.build().unwrap(); { let foo : &Foo = container.resolve_ref::().unwrap(); assert_eq!(foo.get_value(), 17); } { let foo : &mut Foo = container.resolve_mut::().unwrap(); assert_eq!(foo.get_value(), 17); foo.set_value(99); } { let foo : Box = container.resolve::().unwrap(); // consume registration data, `Foo` won't be able to be resolved from this container any longer assert_eq!(foo.get_value(), 99); } { let foo = container.resolve_ref::(); assert!(foo.is_err()); } { let foo = container.resolve_mut::(); assert!(foo.is_err()); } println!("All assertions passed!"); }