Struct di::ServiceProvider

source ·
pub struct ServiceProvider { /* private fields */ }
Expand description

Represents a service provider.

Implementations§

source§

impl ServiceProvider

source

pub fn new(services: HashMap<Type, Vec<ServiceDescriptor>>) -> Self

Initializes a new service provider.

Arguments
source

pub fn get<T: Any + ?Sized>(&self) -> Option<Ref<T>>

Gets a service of the specified type.

source

pub fn get_mut<T: Any + ?Sized>(&self) -> Option<RefMut<T>>

Gets a mutable service of the specified type.

source

pub fn get_by_key<TKey, TSvc: Any + ?Sized>( &self ) -> Option<KeyedRef<TKey, TSvc>>

Gets a keyed service of the specified type.

source

pub fn get_by_key_mut<TKey, TSvc: Any + ?Sized>( &self ) -> Option<KeyedRefMut<TKey, TSvc>>

Gets a keyed, mutable service of the specified type.

source

pub fn get_all<T: Any + ?Sized>(&self) -> impl Iterator<Item = Ref<T>> + '_

Gets all of the services of the specified type.

source

pub fn get_all_mut<T: Any + ?Sized>( &self ) -> impl Iterator<Item = RefMut<T>> + '_

Gets all of the mutable services of the specified type.

source

pub fn get_all_by_key<'a, TKey: 'a, TSvc>( &'a self ) -> impl Iterator<Item = KeyedRef<TKey, TSvc>> + '_
where TSvc: Any + ?Sized,

Gets all of the services of the specified key and type.

source

pub fn get_all_by_key_mut<'a, TKey: 'a, TSvc>( &'a self ) -> impl Iterator<Item = KeyedRefMut<TKey, TSvc>> + '_
where TSvc: Any + ?Sized,

Gets all of the mutable services of the specified key and type.

source

pub fn get_required<T: Any + ?Sized>(&self) -> Ref<T>

Gets a required service of the specified type.

Panics

The requested service of type T does not exist.

source

pub fn get_required_mut<T: Any + ?Sized>(&self) -> RefMut<T>

Gets a required, mutable service of the specified type.

Panics

The requested service of type T does not exist.

source

pub fn get_required_by_key<TKey, TSvc: Any + ?Sized>( &self ) -> KeyedRef<TKey, TSvc>

Gets a required keyed service of the specified type.

Panics

The requested service of type TSvc with key TKey does not exist.

source

pub fn get_required_by_key_mut<TKey, TSvc: Any + ?Sized>( &self ) -> KeyedRefMut<TKey, TSvc>

Gets a required keyed service of the specified type.

Panics

The requested service of type TSvc with key TKey does not exist.

source

pub fn create_scope(&self) -> Self

Creates and returns a new service provider that is used to resolve services from a newly create scope.

Trait Implementations§

source§

impl AsRef<ServiceProvider> for ScopedServiceProvider

source§

fn as_ref(&self) -> &ServiceProvider

Converts this type into a shared reference of the (usually inferred) input type.
source§

impl Borrow<ServiceProvider> for ScopedServiceProvider

source§

fn borrow(&self) -> &ServiceProvider

Immutably borrows from an owned value. Read more
source§

impl Clone for ServiceProvider

source§

fn clone(&self) -> ServiceProvider

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Default for ServiceProvider

source§

fn default() -> Self

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

impl From<&ServiceProvider> for ScopedServiceProvider

source§

fn from(value: &ServiceProvider) -> Self

Converts to this type from the input type.

Auto Trait Implementations§

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> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.