Struct Context

Source
pub struct Context<'pcx> { /* private fields */ }
Expand description

A context in which to store providers for services

Implementations§

Source§

impl Context<'_>

Source

pub fn new() -> Self

Create an empty context

Source

pub fn scoped(&self) -> Context<'_>

Create a sub-context

The retuned context will contain the same elements as the parent context and any elements added to the sub context will not be visible on the original. However, the underlying providers that were added before this call are shared between the two contexts.

Source

pub fn bind_with<'cx, S: Service>( &'cx mut self, provider: impl Provider<'cx, S>, )

Register a new provider for the service S

§Panics

If the service binding fails. See try_bind_with for a fallible version of this function.

Source

pub fn bind_fn<'cx, S: Service>( &'cx mut self, provider_fn: impl Fn(&'cx Context<'_>, S::Argument<'_>) -> S::Output<'cx> + Send + Sync + 'cx, )

Register a function as a provider for the service S

§Panics

If the service binding fails. See try_bind_fn for a fallible version of this function.

Source

pub fn bind<'cx, S, P>(&'cx mut self)
where S: Service, P: Provider<'cx, S> + Default,

Bind the provider P to the service S

§Panics

If the service binding fails. See try_bind for a fallible version of this function.

Source

pub fn unbind<S>(&mut self)
where S: Service,

Delete the provider bound to the service S

§Panics

If the service unbinding fails. See try_unbind for a fallible version of this function.

Source

pub fn resolve<S>(&self) -> S::Output<'_>
where S: Service, S::Argument<'static>: Default,

Resolve the service S using the default service argument.

§Panics

If no provider is registered for this service. See try_resolve for a fallible version of this function.

Source

pub fn resolve_with<S>(&self, arg: S::Argument<'_>) -> S::Output<'_>
where S: Service,

Resolve the service S given the service argument.

§Panics

If no provider is registered for this service. See try_resolve for a fallible version of this function.

Source

pub fn try_bind_with<'cx, S: Service>( &'cx mut self, provider: impl Provider<'cx, S>, ) -> Result<(), BindError>

Try to register a new provider for the service S

§Fails

This function will fail if a provider is already bound to the service.

See bind_with for the panicking version of this function.

Source

pub fn try_bind_fn<'cx, S: Service>( &'cx mut self, provider_fn: impl Fn(&'cx Context<'_>, S::Argument<'_>) -> S::Output<'cx> + Send + Sync + 'cx, ) -> Result<(), BindError>

Try to register a function as a provider for the service S

§Fails

This function will fail if a provider is already bound to the service.

See bind_fn for the panicking version of this function.

Source

pub fn try_bind<'cx, S, P>(&'cx mut self) -> Result<(), BindError>
where S: Service, P: Provider<'cx, S> + Default,

Try to bind the provider P to the service S

§Fails

This function will fail if a provider is already bound to the service.

See bind for the panicking version of this function.

Source

pub fn try_unbind<S>(&mut self) -> Result<(), UnbindError>
where S: Service,

Try to delete the provider bound to the service S.

§Fails

This function will fail if no provider is bound to the service.

See unbind for the panicking version of this function.

Source

pub fn try_resolve<S>(&self) -> Option<S::Output<'_>>
where S: Service, S::Argument<'static>: Default,

Try to resolve the service S using the default service argument.

§Fails

This function will fail if no provider is bound to the service.

See resolve for the panicking version of this function.

Source

pub fn try_resolve_with<S>(&self, arg: S::Argument<'_>) -> Option<S::Output<'_>>
where S: Service,

Try to resolve the service S given the service argument.

§Fails

This function will fail if no provider is bound to the service.

See resolve_with for the panicking version of this function.

Trait Implementations§

Source§

impl Default for Context<'_>

Source§

fn default() -> Self

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

impl Send for Context<'_>

Source§

impl Sync for Context<'_>

Auto Trait Implementations§

§

impl<'pcx> Freeze for Context<'pcx>

§

impl<'pcx> RefUnwindSafe for Context<'pcx>

§

impl<'pcx> Unpin for Context<'pcx>

§

impl<'pcx> UnwindSafe for Context<'pcx>

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

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.