pub struct Context<'pcx> { /* private fields */ }Expand description
A context in which to store providers for services
Implementations
sourceimpl 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::Output<'cx> + 'cx
)
pub fn bind_fn<'cx, S: Service>(
&'cx mut self,
provider_fn: impl Fn(&'cx Context<'_>) -> S::Output<'cx> + '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: Service>(&self) -> S::Output<'_>
pub fn resolve<S: Service>(&self) -> S::Output<'_>
Resolve the service S based on the already registered providers
Panics
If no provider is registered for this service. See try_resolve for a
fallible version of this function.