[−][src]Struct inject::Container
Contains providers for resolvable types.
The macro container!
simplifies the construction of Container
s 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
Provider
s and RefProvider
s.
pub fn install<T: Inject, P: 'static + Provider<ProvidedType = T>>(
&mut self,
provider: P
)
[src]
&mut self,
provider: P
)
Install a Provider
into this Container
pub fn install_ref<T: Inject, P: 'static + RefProvider<ProvidedRef = T>>(
&mut self,
provider: P
)
[src]
&mut self,
provider: P
)
Install a RefProvider
into this Container
pub fn get<T: Inject>(&self) -> Result<T, InjectError>
[src]
Resolve a value-type from the installed Provider
s.
pub fn get_ref<T: 'static>(&self) -> Result<&T, InjectError>
[src]
Resolve a reference-type from the installed RefProvider
s.
Trait Implementations
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]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T> Inject for T where
T: 'static,
[src]
T: 'static,
impl<T> InjectExt for T where
T: Inject + Default,
[src]
T: Inject + Default,
fn inject(container: &Container) -> Result<Self, InjectError>
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,