pub struct Context<'pcx> { /* private fields */ }
Expand description
A context in which to store providers for services
Implementations§
Source§impl Context<'_>
impl Context<'_>
Sourcepub fn scoped(&self) -> Context<'_>
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.
Sourcepub fn bind_with<'cx, S: Service>(
&'cx mut self,
provider: impl Provider<'cx, S>,
)
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.
Sourcepub fn bind_fn<'cx, S: Service>(
&'cx mut self,
provider_fn: impl Fn(&'cx Context<'_>, S::Argument<'_>) -> S::Output<'cx> + Send + Sync + 'cx,
)
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.
Sourcepub fn unbind<S>(&mut self)where
S: Service,
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.
Sourcepub fn resolve<S>(&self) -> S::Output<'_>
pub fn resolve<S>(&self) -> S::Output<'_>
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.
Sourcepub fn resolve_with<S>(&self, arg: S::Argument<'_>) -> S::Output<'_>where
S: Service,
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.
Sourcepub fn try_bind_with<'cx, S: Service>(
&'cx mut self,
provider: impl Provider<'cx, S>,
) -> Result<(), BindError>
pub fn try_bind_with<'cx, S: Service>( &'cx mut self, provider: impl Provider<'cx, S>, ) -> Result<(), BindError>
Sourcepub 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>
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>
Sourcepub fn try_unbind<S>(&mut self) -> Result<(), UnbindError>where
S: Service,
pub fn try_unbind<S>(&mut self) -> Result<(), UnbindError>where
S: Service,
Sourcepub fn try_resolve<S>(&self) -> Option<S::Output<'_>>
pub fn try_resolve<S>(&self) -> Option<S::Output<'_>>
Sourcepub fn try_resolve_with<S>(&self, arg: S::Argument<'_>) -> Option<S::Output<'_>>where
S: Service,
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.