1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#![feature(associated_type_defaults)] 
#![feature(reflect_marker)]
#![feature(core_intrinsics)]
#![feature(box_syntax)]

#[macro_use] extern crate downcast;

mod reflect;
mod error;
mod guards;
mod factory;
mod methods;
mod container;
mod ioc;
mod staged_ioc;

pub use reflect::*;
pub use error::*;
pub use guards::*;
pub use factory::*;
pub use methods::*;
pub use container::*;
pub use ioc::*;
pub use staged_ioc::*;

/// Alias for `Read`.
pub use Read as R;

/// Alias for `Write`.
pub use Write as W;

// NOTE old code
// TODO move this into tests/examples
/*#[macro_use] 
extern crate lazy_static;

#[test]
fn read_trait_object(){    
    macro_rules! service {
        ($ty:ty, $name:expr) => {
            impl ServiceReflect for $ty {
                fn key() -> &'static String {
                    lazy_static!{
                        static ref RET: String = $name.into();
                    }
                    &*RET
                }
            }

            impl Into<Box<DefaultBase>> for Box<$ty> {
                fn into(self) -> Box<DefaultBase> { self }
            }
        };
    }

    trait Foo: Sync {
        fn foo(&self) -> &str;
    }

    service!(Box<Foo>, "foo");

    struct FooBar;

    impl Foo for FooBar{
        fn foo(&self) -> &str { "bar" }  
    }

    let mut builder = ContainerBuilder::<String>::new();
    builder.register(Box::new(FooBar) as Box<Foo>);

    let ioc = builder.build();

    assert_eq!("bar", ioc.read::<Box<Foo>>().unwrap().foo());
}*/