pub struct Context { /* private fields */ }Expand description
Root and child dependency containers for Cordis plugins.
Cloning a context is cheap. Child contexts share all runtime services while carrying immutable scope/intercept/metadata overlays and the current fiber.
Implementations§
Source§impl Context
impl Context
Sourcepub fn new() -> Self
pub fn new() -> Self
Create a root context and install the core reflection, registry, event, and logger services.
Sourcepub fn same_root(&self, other: &Context) -> bool
pub fn same_root(&self, other: &Context) -> bool
Return whether two contexts belong to the same root application.
Sourcepub fn base_url(&self) -> Option<&str>
pub fn base_url(&self) -> Option<&str>
Return the base URL inherited by this context, when set.
Sourcepub fn with_base_url(&self, base_url: impl Into<Arc<str>>) -> Context
pub fn with_base_url(&self, base_url: impl Into<Arc<str>>) -> Context
Derive a child context with a new base URL.
Sourcepub fn extend<T>(&self, name: impl Into<String>, value: T) -> Context
pub fn extend<T>(&self, name: impl Into<String>, value: T) -> Context
Derive a child context carrying arbitrary metadata.
Sourcepub fn extend_value(&self, name: impl Into<String>, value: Value) -> Context
pub fn extend_value(&self, name: impl Into<String>, value: Value) -> Context
Derive a child context carrying type-erased metadata.
Sourcepub fn new_isolation(&self) -> Isolation
pub fn new_isolation(&self) -> Isolation
Allocate a globally unique isolation label.
Sourcepub fn isolate(&self, name: impl Into<String>) -> Context
pub fn isolate(&self, name: impl Into<String>) -> Context
Create a child context with a fresh independent service scope for
name.
Sourcepub fn isolate_with(&self, name: impl Into<String>, label: Isolation) -> Context
pub fn isolate_with(&self, name: impl Into<String>, label: Isolation) -> Context
Create a child context using a supplied scope label. Reusing the label joins otherwise separate context branches to the same service scope.
A scope holds one implementation per slot, and every name isolated
with the same label maps to that one slot: only one of those names
can be provided there, and providing a second fails with
DuplicateService.
Sourcepub fn isolate_many(
&self,
names: impl IntoIterator<Item = impl Into<String>>,
label: Option<Isolation>,
) -> Context
pub fn isolate_many( &self, names: impl IntoIterator<Item = impl Into<String>>, label: Option<Isolation>, ) -> Context
Create a child context with several service names isolated together.
All names share one scope label and therefore one implementation
slot, matching the upstream single-slot scope model: provide exactly
one of them in this branch — providing a second name fails with
DuplicateService — and inject
only that name from sibling plugins. Use separate labels (or
isolate) when several of the names need independent
implementations.
Sourcepub fn intercept<T>(&self, name: impl Into<String>, config: T) -> Context
pub fn intercept<T>(&self, name: impl Into<String>, config: T) -> Context
Add service-specific intercept configuration below this context.
Sourcepub fn intercept_value(&self, name: impl Into<String>, config: Value) -> Context
pub fn intercept_value(&self, name: impl Into<String>, config: Value) -> Context
Add type-erased intercept configuration.
Sourcepub fn intercepts<T>(&self, name: &str) -> Result<Vec<Arc<T>>>
pub fn intercepts<T>(&self, name: &str) -> Result<Vec<Arc<T>>>
Return typed intercept configs in ancestor-to-descendant order.
Sourcepub fn with_filter<F>(&self, filter: F) -> Context
pub fn with_filter<F>(&self, filter: F) -> Context
Attach an event listener filter to a derived context.
Sourcepub fn events(&self) -> EventsService
pub fn events(&self) -> EventsService
Return the events service bound to this context.
Sourcepub fn reflect(&self) -> ReflectService
pub fn reflect(&self) -> ReflectService
Return the reflection/service store bound to this context.
Sourcepub fn registry(&self) -> RegistryService
pub fn registry(&self) -> RegistryService
Return the plugin registry bound to this context.
Sourcepub fn named_logger(&self, name: impl Into<String>) -> Logger
pub fn named_logger(&self, name: impl Into<String>) -> Logger
Return an explicitly named logger.
Sourcepub fn logger_service(&self) -> LoggerService
pub fn logger_service(&self) -> LoggerService
Return the logger service bound to this context.
Sourcepub fn effect<F>(
&self,
label: impl Into<String>,
dispose: F,
) -> Result<EffectHandle>
pub fn effect<F>( &self, label: impl Into<String>, dispose: F, ) -> Result<EffectHandle>
Register a synchronous cleanup operation on the current fiber.
Sourcepub fn effect_infallible<F>(
&self,
label: impl Into<String>,
dispose: F,
) -> Result<EffectHandle>
pub fn effect_infallible<F>( &self, label: impl Into<String>, dispose: F, ) -> Result<EffectHandle>
Register an infallible synchronous cleanup operation.
Sourcepub fn effect_async<F, Fut>(
&self,
label: impl Into<String>,
dispose: F,
) -> Result<EffectHandle>
pub fn effect_async<F, Fut>( &self, label: impl Into<String>, dispose: F, ) -> Result<EffectHandle>
Register an asynchronous cleanup operation.
Sourcepub fn provide<T>(
&self,
name: impl Into<String>,
value: T,
) -> Result<EffectHandle>
pub fn provide<T>( &self, name: impl Into<String>, value: T, ) -> Result<EffectHandle>
Provide a concrete service in this context’s isolation scope.
Sourcepub fn provide_arc<T>(
&self,
name: impl Into<String>,
value: Arc<T>,
) -> Result<EffectHandle>
pub fn provide_arc<T>( &self, name: impl Into<String>, value: Arc<T>, ) -> Result<EffectHandle>
Provide an existing Arc without wrapping it in a second Arc.
Sourcepub fn get<T>(&self, name: &str) -> Result<Option<Arc<T>>>
pub fn get<T>(&self, name: &str) -> Result<Option<Arc<T>>>
Read a service without enforcing an inject declaration.
Sourcepub fn get_unchecked<T>(&self, name: &str) -> Result<Option<Arc<T>>>
pub fn get_unchecked<T>(&self, name: &str) -> Result<Option<Arc<T>>>
Read a service even while its provider is loading or unloading.
Sourcepub fn set<T>(&self, name: &str, value: T) -> Result<()>
pub fn set<T>(&self, name: &str, value: T) -> Result<()>
Replace a service value. Only its providing fiber may do this.
Sourcepub fn notify<I, S>(&self, names: I) -> Vec<Fiber>
pub fn notify<I, S>(&self, names: I) -> Vec<Fiber>
Re-evaluate dependency availability for the named services.
Sourcepub fn accessor(
&self,
name: impl Into<String>,
accessor: Accessor,
) -> Result<EffectHandle>
pub fn accessor( &self, name: impl Into<String>, accessor: Accessor, ) -> Result<EffectHandle>
Register a dynamic computed property.
Sourcepub fn on<F>(
&self,
name: impl Into<String>,
listener: F,
) -> Result<EffectHandle>
pub fn on<F>( &self, name: impl Into<String>, listener: F, ) -> Result<EffectHandle>
Register an event listener owned by this context’s fiber.
Sourcepub fn on_with<F>(
&self,
name: impl Into<String>,
listener: F,
options: EventOptions,
) -> Result<EffectHandle>
pub fn on_with<F>( &self, name: impl Into<String>, listener: F, options: EventOptions, ) -> Result<EffectHandle>
Register a listener with placement and filtering options.
Sourcepub fn on_async<F, Fut>(
&self,
name: impl Into<String>,
listener: F,
) -> Result<EffectHandle>
pub fn on_async<F, Fut>( &self, name: impl Into<String>, listener: F, ) -> Result<EffectHandle>
Register an asynchronous event listener.
Sourcepub fn once<F>(
&self,
name: impl Into<String>,
listener: F,
) -> Result<EffectHandle>
pub fn once<F>( &self, name: impl Into<String>, listener: F, ) -> Result<EffectHandle>
Register a one-shot event listener.
Sourcepub fn emit(
&self,
name: impl Into<String>,
args: impl IntoIterator<Item = EventValue>,
) -> Result<()>
pub fn emit( &self, name: impl Into<String>, args: impl IntoIterator<Item = EventValue>, ) -> Result<()>
Emit an event synchronously.
Sourcepub async fn parallel(
&self,
name: impl Into<String>,
args: impl IntoIterator<Item = EventValue>,
) -> Result<()>
pub async fn parallel( &self, name: impl Into<String>, args: impl IntoIterator<Item = EventValue>, ) -> Result<()>
Run all matching listeners concurrently.
Sourcepub async fn serial(
&self,
name: impl Into<String>,
args: impl IntoIterator<Item = EventValue>,
) -> EventResult
pub async fn serial( &self, name: impl Into<String>, args: impl IntoIterator<Item = EventValue>, ) -> EventResult
Await listeners in order until one returns a bail value.
Sourcepub fn bail(
&self,
name: impl Into<String>,
args: impl IntoIterator<Item = EventValue>,
) -> EventResult
pub fn bail( &self, name: impl Into<String>, args: impl IntoIterator<Item = EventValue>, ) -> EventResult
Run listeners synchronously until one returns a bail value.
Sourcepub fn waterfall<F>(
&self,
name: impl Into<String>,
args: impl IntoIterator<Item = EventValue>,
inner: F,
) -> EventResult
pub fn waterfall<F>( &self, name: impl Into<String>, args: impl IntoIterator<Item = EventValue>, inner: F, ) -> EventResult
Compose listeners around an innermost synchronous callback.
Sourcepub fn plugin<P, C>(&self, plugin: P, config: C) -> Fiber
pub fn plugin<P, C>(&self, plugin: P, config: C) -> Fiber
Start a plugin and return its lifecycle fiber.
Sourcepub fn plugin_default<P>(&self, plugin: P) -> Fiberwhere
P: IntoPlugin,
pub fn plugin_default<P>(&self, plugin: P) -> Fiberwhere
P: IntoPlugin,
Start a plugin with unit configuration.
Sourcepub fn plugin_object<P, C>(&self, plugin: P, config: C) -> Fiber
pub fn plugin_object<P, C>(&self, plugin: P, config: C) -> Fiber
Wrap and start a concrete Plugin implementation.
Sourcepub fn plugin_object_default<P>(&self, plugin: P) -> Fiberwhere
P: Plugin,
pub fn plugin_object_default<P>(&self, plugin: P) -> Fiberwhere
P: Plugin,
Start a concrete plugin implementation with unit configuration.
Source§impl Context
impl Context
Sourcepub fn provide_service<S>(&self, service: S) -> Result<EffectHandle>where
S: Service,
pub fn provide_service<S>(&self, service: S) -> Result<EffectHandle>where
S: Service,
Provide a typed service under Service::NAME.
Sourcepub fn provide_service_arc<S>(&self, service: Arc<S>) -> Result<EffectHandle>where
S: Service,
pub fn provide_service_arc<S>(&self, service: Arc<S>) -> Result<EffectHandle>where
S: Service,
Provide an existing shared typed service.