pub struct Container<'a> { /* private fields */ }Expand description
Represents a store to register and retrieve objects.
Implementations
sourceimpl<'a> Container<'a>
impl<'a> Container<'a>
sourcepub fn add_scoped<T, F>(&mut self, f: F) -> Result<(), Provider<'_>> where
T: Send + Sync + 'static,
F: Fn() -> T + Send + Sync + 'static,
pub fn add_scoped<T, F>(&mut self, f: F) -> Result<(), Provider<'_>> where
T: Send + Sync + 'static,
F: Fn() -> T + Send + Sync + 'static,
Adds a scoped factory function.
Returns
Ok(()) if the provider was added, or Err(Provider) if
there is a provider registered for that type.
sourcepub fn add_scoped_with_name<T, F>(
&mut self,
name: &str,
f: F
) -> Result<(), Provider<'_>> where
T: Send + Sync + 'static,
F: Fn() -> T + Send + Sync + 'static,
pub fn add_scoped_with_name<T, F>(
&mut self,
name: &str,
f: F
) -> Result<(), Provider<'_>> where
T: Send + Sync + 'static,
F: Fn() -> T + Send + Sync + 'static,
Adds a scoped factory function with a name.
Returns
Ok(()) if the provider was added, or Err(Provider) if
there is a provider registered for that type.
sourcepub fn add_singleton<T>(&mut self, value: T) -> Result<(), Provider<'_>> where
T: Send + Sync + 'static,
pub fn add_singleton<T>(&mut self, value: T) -> Result<(), Provider<'_>> where
T: Send + Sync + 'static,
Adds a singleton.
Returns
Ok(()) if the provider was added, or Err(Provider) if
there is a provider registered for that type.
sourcepub fn add_singleton_with_name<T>(
&mut self,
name: &str,
value: T
) -> Result<(), Provider<'_>> where
T: Send + Sync + 'static,
pub fn add_singleton_with_name<T>(
&mut self,
name: &str,
value: T
) -> Result<(), Provider<'_>> where
T: Send + Sync + 'static,
Adds a singleton with a name.
Returns
Ok(()) if the provider was added, or Err(Provider) if
there is a provider registered for that type.
pub fn add_lazy_singleton<T, F>(&mut self, f: F) -> Result<(), Provider<'_>> where
T: Send + Sync + 'static,
F: FnOnce(&Container<'_>) -> T + Send + Sync + 'static,
pub fn add_lazy_singleton_with_name<T, F>(
&mut self,
name: &str,
f: F
) -> Result<(), Provider<'_>> where
T: Send + Sync + 'static,
F: FnOnce(&Container<'_>) -> T + Send + Sync + 'static,
sourcepub fn add_deps<T>(&mut self) -> Result<(), Provider<'_>> where
T: Inject + Send + Sync + 'static,
pub fn add_deps<T>(&mut self) -> Result<(), Provider<'_>> where
T: Inject + Send + Sync + 'static,
Adds a scoped Inject that depends on others providers.
Returns
Ok(()) if the provider was added, or Err(Provider) if
there is a provider registered for that type.
sourcepub fn add_deps_with_name<T>(&mut self, name: &str) -> Result<(), Provider<'_>> where
T: Inject + Send + Sync + 'static,
pub fn add_deps_with_name<T>(&mut self, name: &str) -> Result<(), Provider<'_>> where
T: Inject + Send + Sync + 'static,
Adds a scoped named Inject that depends on others providers.
Returns
Ok(()) if the provider was added, or Err(Provider) if
there is a provider registered for that type.
sourcepub fn add_deps_fn<T, F>(&mut self, f: F) -> Result<(), Provider<'_>> where
T: Send + Sync + 'static,
F: Fn(&Container<'_>) -> T + Send + Sync + 'static,
pub fn add_deps_fn<T, F>(&mut self, f: F) -> Result<(), Provider<'_>> where
T: Send + Sync + 'static,
F: Fn(&Container<'_>) -> T + Send + Sync + 'static,
Adds a scoped Inject that depends on others providers.
Returns
Ok(()) if the provider was added, or Err(Provider) if
there is a provider registered for that type.
sourcepub fn add_deps_fn_with_name<T, F>(
&mut self,
name: &str,
f: F
) -> Result<(), Provider<'_>> where
T: Send + Sync + 'static,
F: Fn(&Container<'_>) -> T + Send + Sync + 'static,
pub fn add_deps_fn_with_name<T, F>(
&mut self,
name: &str,
f: F
) -> Result<(), Provider<'_>> where
T: Send + Sync + 'static,
F: Fn(&Container<'_>) -> T + Send + Sync + 'static,
Adds a scoped named Inject that depends on others providers.
Returns
Ok(()) if the provider was added, or Err(Provider) if
there is a provider registered for that type.
sourcepub fn get<T>(&self) -> Option<Resolved<T>> where
T: Send + Sync + 'static,
pub fn get<T>(&self) -> Option<Resolved<T>> where
T: Send + Sync + 'static,
Returns a value registered for the given type or None
if no provider is register for the given type.
The returning value could be either scoped or a singleton.
sourcepub fn get_with_name<T>(&self, name: &str) -> Option<Resolved<T>> where
T: Send + Sync + 'static,
pub fn get_with_name<T>(&self, name: &str) -> Option<Resolved<T>> where
T: Send + Sync + 'static,
Returns a value registered for the given type and name or None
if no provider is register for the given type.
The returning value could be either scoped or a singleton.
sourcepub fn get_scoped<T>(&self) -> Option<T> where
T: Send + Sync + 'static,
pub fn get_scoped<T>(&self) -> Option<T> where
T: Send + Sync + 'static,
Returns a value registered for the given type, or None
if no provider is register for the given type.
sourcepub fn get_scoped_with_name<T>(&self, name: &str) -> Option<T> where
T: Send + Sync + 'static,
pub fn get_scoped_with_name<T>(&self, name: &str) -> Option<T> where
T: Send + Sync + 'static,
Returns a value registered for the given type and name, or None
if no provider is register for the given type and name.
sourcepub fn get_singleton<T>(&self) -> Option<Singleton<T>> where
T: Send + Sync + 'static,
pub fn get_singleton<T>(&self) -> Option<Singleton<T>> where
T: Send + Sync + 'static,
Returns a singleton registered for the given type, or None
if no provider is register for the given type.
sourcepub fn get_singleton_with_name<T>(&self, name: &str) -> Option<Singleton<T>> where
T: Send + Sync + 'static,
pub fn get_singleton_with_name<T>(&self, name: &str) -> Option<Singleton<T>> where
T: Send + Sync + 'static,
Returns a singleton registered for the given type and name, or None
if no provider is register for the given type and name.
sourcepub fn contains(&self, key: InjectionKey<'_>) -> bool
pub fn contains(&self, key: InjectionKey<'_>) -> bool
Returns true if the Container have a provider for the given InjectionKey.
sourcepub fn remove(&mut self, key: InjectionKey<'a>) -> Option<Provider<'_>>
pub fn remove(&mut self, key: InjectionKey<'a>) -> Option<Provider<'_>>
Removes the provider with the given InjectionKey and returns it,
or None if the provider is not found.
sourcepub fn providers(&self) -> Values<'_, InjectionKey<'a>, Provider<'_>>
pub fn providers(&self) -> Values<'_, InjectionKey<'a>, Provider<'_>>
Returns an iterator over the providers of this container.
sourcepub fn iter(&self) -> Iter<'_, InjectionKey<'a>, Provider<'_>>
pub fn iter(&self) -> Iter<'_, InjectionKey<'a>, Provider<'_>>
Returns an iterator over the keys and providers of this container.
Trait Implementations
Auto Trait Implementations
impl<'a> !RefUnwindSafe for Container<'a>
impl<'a> Send for Container<'a>
impl<'a> Sync for Container<'a>
impl<'a> Unpin for Container<'a>
impl<'a> !UnwindSafe for Container<'a>
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcefn clone_into(&self, target: &mut T)
fn clone_into(&self, target: &mut T)
toowned_clone_into)Uses borrowed data to replace owned data, usually by cloning. Read more