pub struct Container<P> {
    pub config: Config,
    pub components: HashMap<TypeId, RcAny>,
    /* private fields */
}

Fields§

§config: Config§components: HashMap<TypeId, RcAny>

Implementations§

source§

impl<P> Container<P>

source

pub fn new() -> Container<P>

Examples found in repository?
examples/1_get_started.rs (line 30)
29
30
31
32
33
34
35
fn main() {
    let mut container = Container::<profiles::Default>::new();

    let component = Provider::<SomeComp>::get(&mut container);

    component.interface.demo();
}
More examples
Hide additional examples
examples/2_modules.rs (line 50)
49
50
51
52
53
54
55
56
57
fn main() {
    let mut container = Container::<profiles::Dev>::new();

    let mut user_repository = Provider::<dyn UserRepository>::create(&mut container);

    user_repository.save(12, "John".to_string());

    println!("Found user with id = 12: {:?}", user_repository.find(12));
}
examples/3_inject_options_list.rs (line 96)
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
fn main() {
    let mut container = Container::<profiles::Default>::new();

    let comp = Provider::<Comp>::get_ref(&mut container);
    comp.comp();
    comp.int();
    comp.int2();

    let comp = Provider::<dyn Interface>::get_ref(&mut container);
    comp.int();


    let mut container = Container::<profiles::Dev>::new();
    let comp = Provider::<dyn Interface>::get_ref(&mut container);
    comp.int();

    let comp = Provider::<dyn Interface2>::get_ref(&mut container);
    comp.int2();


    println!("Using profile: {}", APP_PROFILE.as_str());
    let comp = inject!(Comp: profiles::Default, profiles::Dev);
    comp.comp();
}

Trait Implementations§

source§

impl<P> Default for Container<P>

source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl<P> !RefUnwindSafe for Container<P>

§

impl<P> !Send for Container<P>

§

impl<P> !Sync for Container<P>

§

impl<P> Unpin for Container<P>
where P: Unpin,

§

impl<P> !UnwindSafe for Container<P>

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.