[][src]Struct inject::Container

pub struct Container { /* fields omitted */ }

Contains providers for resolvable types.

The macro container! simplifies the construction of Containers calling container.install(..) and container.install_ref(..) (if ref keyword is supplied) on the macro arguments provided.

To resolve a dependecy by using the installed providers, methods container.get() and container.get_ref() are called for values and references, respectively.

Example

use ::inject::*;

let reference_provider = Box::new(5usize);
let container = container![
    |container: &Container| Ok(2i32),
    ref reference_provider,
];

assert_eq!(5usize, *container.get_ref().unwrap());
assert_eq!(2i32, container.get().unwrap());

Implementations

impl Container[src]

pub fn new() -> Container[src]

Create a new Container, used to store implementors of Providers and RefProviders.

pub fn install<T: Inject, P: 'static + Provider<ProvidedType = T>>(
    &mut self,
    provider: P
)
[src]

Install a Provider into this Container

pub fn install_ref<T: Inject, P: 'static + RefProvider<ProvidedRef = T>>(
    &mut self,
    provider: P
)
[src]

Install a RefProvider into this Container

pub fn get<T: Inject>(&self) -> Result<T, InjectError>[src]

Resolve a value-type from the installed Providers.

pub fn get_ref<T: 'static>(&self) -> Result<&T, InjectError>[src]

Resolve a reference-type from the installed RefProviders.

Trait Implementations

impl Debug for Container[src]

impl Default for Container[src]

Auto Trait Implementations

impl !RefUnwindSafe for Container

impl !Send for Container

impl !Sync for Container

impl Unpin for Container

impl !UnwindSafe for Container

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T> Inject for T where
    T: 'static, 
[src]

impl<T> InjectExt for T where
    T: Inject + Default
[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.