Skip to main content

Resolver

Struct Resolver 

Source
pub struct Resolver<'a> { /* private fields */ }
Expand description

Resolves dependencies while a service is being constructed.

Each construction gets its own frame linked to the frame that requested it, so the chain of services under construction lives on the stack.

Use it only on the constructing thread. Construction of cached instances is serialised per container and per scope, so handing a resolver to another thread and waiting for it deadlocks.

Implementations§

Source§

impl<'a> Resolver<'a>

Source

pub fn resolve<T>(&self) -> Result<Arc<T>, ResolveError>
where T: Send + Sync + 'static + ?Sized,

Resolves a dependency of the service under construction.

When T is registered more than once, the last registration wins; use resolve_all for every one.

Source

pub fn resolve_all<T>(&self) -> Result<Vec<Arc<T>>, ResolveError>
where T: Send + Sync + 'static + ?Sized,

Resolves every registration of T, in registration order. The first failure fails the whole call; nothing is cached for the failed member.

Source

pub fn construction_error( &self, source: impl Into<Box<dyn Error + Sync + Send>>, ) -> ResolveError

Wraps a constructor failure with the current dependency path.

Trait Implementations§

Source§

impl Debug for Resolver<'_>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'a> !RefUnwindSafe for Resolver<'a>

§

impl<'a> !UnwindSafe for Resolver<'a>

§

impl<'a> Freeze for Resolver<'a>

§

impl<'a> Send for Resolver<'a>

§

impl<'a> Sync for Resolver<'a>

§

impl<'a> Unpin for Resolver<'a>

§

impl<'a> UnsafeUnpin for Resolver<'a>

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>,

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

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

Source§

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.