pub struct Ctx { /* private fields */ }Expand description
Typed service registry (Cordis ctx container). Service keys are stable:
the key is the TypeId of the trait-object type (dyn Greeter) or of a
concrete type; values are Arc<dyn Any + Send + Sync> wrappers around
Arc<S>.
Also carries the typed-event handler registry (see crate::dispatch):
ctx.on* registers handlers, ctx.emit/parallel/serial/waterfall/
bail dispatch them.
Implementations§
Source§impl Ctx
impl Ctx
pub fn new() -> Self
Sourcepub fn provide<S: ?Sized + Service>(
&self,
svc: Arc<S>,
) -> Result<Disposer, PluginError>
pub fn provide<S: ?Sized + Service>( &self, svc: Arc<S>, ) -> Result<Disposer, PluginError>
Registers svc under the stable service key S and returns the
Disposer that removes exactly this registration.
Sourcepub fn resolve<S: ?Sized + Service>(&self) -> Option<Arc<S>>
pub fn resolve<S: ?Sized + Service>(&self) -> Option<Arc<S>>
Looks the service for key S up by trait type; None if absent.
Sourcepub fn contains_service<S: ?Sized + Service>(&self) -> bool
pub fn contains_service<S: ?Sized + Service>(&self) -> bool
Whether a service currently occupies the key S.
Source§impl Ctx
impl Ctx
Sourcepub fn on<E, F>(&self, handler: F) -> Disposer
pub fn on<E, F>(&self, handler: F) -> Disposer
Registers an observer for E (used by both emit and parallel).
The returned Disposer unregisters exactly this observer.
Sourcepub fn on_serial<E, R, F>(&self, handler: F) -> Disposer
pub fn on_serial<E, R, F>(&self, handler: F) -> Disposer
Registers an ordered handler for E producing R.
Sourcepub fn on_waterfall<E, T, M>(&self, middleware: M) -> Disposer
pub fn on_waterfall<E, T, M>(&self, middleware: M) -> Disposer
Registers one waterfall middleware step for (E, T).
Sourcepub fn on_bail<E, T, F>(&self, handler: F) -> Disposer
pub fn on_bail<E, T, F>(&self, handler: F) -> Disposer
Registers a bail handler for (E, T): Some(value) bails the
dispatch, None defers to the next handler.
Sourcepub async fn emit<E>(&self, event: &E)
pub async fn emit<E>(&self, event: &E)
Runs all observers of E in registration order; no results.
Sourcepub async fn parallel<E>(&self, event: &E)
pub async fn parallel<E>(&self, event: &E)
Runs all observers of E concurrently and awaits every one.
Sourcepub async fn serial<E, R>(&self, event: &E) -> Vec<R>
pub async fn serial<E, R>(&self, event: &E) -> Vec<R>
Awaits each serial handler of E in registration order and returns
every handler’s value, in order.
Sourcepub async fn waterfall<E, T>(&self, event: &E, initial: T) -> T
pub async fn waterfall<E, T>(&self, event: &E, initial: T) -> T
Threads initial through the waterfall middleware chain for (E, T)
in registration order; the first Flow::Stop short-circuits the
chain (later middleware must not run).