pub struct Injected<D> { /* private fields */ }Expand description
A plugin context whose typed accesses are checked against its declared
dependencies D at compile time: get::<S>() only compiles if S is in D.
Implementations§
Source§impl<D> Injected<D>where
D: Deps,
impl<D> Injected<D>where
D: Deps,
pub fn new(ctx: Context) -> Injected<D>
Sourcepub fn get<S, I>(&self) -> Result<Svc<S>, AccessError>
pub fn get<S, I>(&self) -> Result<Svc<S>, AccessError>
A declared dependency, read through the committed view:
ctx.get::<Database, _>() (the _ is its inferred position in D).
Methods from Deref<Target = Context>§
pub fn fiber_id(&self) -> FiberId
pub fn is_root(&self) -> bool
Sourcepub fn same_root(&self, other: &Context) -> bool
pub fn same_root(&self, other: &Context) -> bool
Whether both contexts belong to the same root.
Sourcepub fn ptr_eq(&self, other: &Context) -> bool
pub fn ptr_eq(&self, other: &Context) -> bool
Whether both handles denote the very same derived context.
Sourcepub fn isolate(&self, key: impl Into<Key>) -> Context
pub fn isolate(&self, key: impl Into<Key>) -> Context
Derives a context in which key lives in a fresh, private realm.
Sourcepub fn isolate_in(&self, key: impl Into<Key>, realm: RealmId) -> Context
pub fn isolate_in(&self, key: impl Into<Key>, realm: RealmId) -> Context
Derives a context in which key lives in the given (shared) realm.
Sourcepub fn intercept(&self, key: impl Into<Key>, meta: Value) -> Context
pub fn intercept(&self, key: impl Into<Key>, meta: Value) -> Context
Derives a context carrying interception metadata for key.
Sourcepub fn extend(&self) -> Context
pub fn extend(&self) -> Context
Derives a context with its own mutable isolation and interception
tables (see Overlay).
Sourcepub fn extend_with(&self, overlay: &Arc<Overlay>) -> Context
pub fn extend_with(&self, overlay: &Arc<Overlay>) -> Context
Derives a context backed by a given overlay; several contexts may share one overlay.
Sourcepub fn overlay(&self) -> Option<Arc<Overlay>>
pub fn overlay(&self) -> Option<Arc<Overlay>>
The overlay of this very context, if it was made by extend.
Sourcepub fn reparent(&self, parent: &Context) -> Context
pub fn reparent(&self, parent: &Context) -> Context
Re-attaches this context, with everything derived below it, under
parent. Like a re-pointed prototype, the returned handle belongs to
parent’s fiber.
Sourcepub fn parent_overlay(&self) -> Option<Arc<Overlay>>
pub fn parent_overlay(&self) -> Option<Arc<Overlay>>
The overlay this context is directly derived from, if any.
Sourcepub fn tag(&self) -> Option<u64>
pub fn tag(&self) -> Option<u64>
The tag of the nearest tagged overlay on the derivation chain.
Sourcepub fn is_within(&self, ancestor: &Context) -> bool
pub fn is_within(&self, ancestor: &Context) -> bool
Whether this context is derived from ancestor (or is it).
Sourcepub fn isolated_keys(&self) -> Vec<Key>
pub fn isolated_keys(&self) -> Vec<Key>
Every key isolated somewhere on this context’s derivation chain.
Sourcepub fn realm(&self, key: &str) -> Option<RealmId>
pub fn realm(&self, key: &str) -> Option<RealmId>
The realm key resolves to from this context, if it has one yet.
Sourcepub fn has_isolation(&self, key: &str) -> bool
pub fn has_isolation(&self, key: &str) -> bool
Whether this context isolates key itself rather than inheriting
the root realm.
Sourcepub fn intercepts(&self, key: &str) -> Vec<Value>
pub fn intercepts(&self, key: &str) -> Vec<Value>
Interception metadata for key from the outermost context to this one.
Sourcepub fn intercept_meta<T>(&self, key: &str) -> Twhere
T: DeserializeOwned + Default,
pub fn intercept_meta<T>(&self, key: &str) -> Twhere
T: DeserializeOwned + Default,
Interception metadata for key, merged right-biased and deserialized.
Malformed metadata yields the default.
Sourcepub fn deps<D>(&self) -> Result<<D as Deps>::Output, AccessError>where
D: Deps,
pub fn deps<D>(&self) -> Result<<D as Deps>::Output, AccessError>where
D: Deps,
Accesses a tuple of declared services through the committed view.
Sourcepub fn effect_sync<F>(
&self,
label: impl Into<String>,
body: F,
) -> Result<EffectHandle, Error>
pub fn effect_sync<F>( &self, label: impl Into<String>, body: F, ) -> Result<EffectHandle, Error>
Runs a synchronous effect body. If it fails, whatever it collected is disposed and the error is returned.
Sourcepub fn effect<F, Fut>(
&self,
label: impl Into<String>,
body: F,
) -> Result<EffectHandle, Error>
pub fn effect<F, Fut>( &self, label: impl Into<String>, body: F, ) -> Result<EffectHandle, Error>
Starts an asynchronous effect. The body is spawned and never dropped
half-way; disposal waits for it to reach its end or an iteration
boundary. A failure disposes what it collected, is logged, and is
reported by EffectHandle::ready.
Sourcepub fn on_dispose(
&self,
f: impl FnOnce() + Send + 'static,
) -> Result<EffectHandle, Error>
pub fn on_dispose( &self, f: impl FnOnce() + Send + 'static, ) -> Result<EffectHandle, Error>
Registers a plain inverse on the current fiber.
Sourcepub fn defer(
&self,
label: impl Into<String>,
disposer: Disposer,
) -> Result<EffectHandle, Error>
pub fn defer( &self, label: impl Into<String>, disposer: Disposer, ) -> Result<EffectHandle, Error>
Registers an arbitrary inverse on the current fiber.
Sourcepub fn on<E>(
&self,
listener: impl Fn(&E) -> <E as Event>::Output + Send + Sync + 'static,
) -> Result<EffectHandle, Error>where
E: Event,
pub fn on<E>(
&self,
listener: impl Fn(&E) -> <E as Event>::Output + Send + Sync + 'static,
) -> Result<EffectHandle, Error>where
E: Event,
Registers a listener as an effect of the current fiber.
Sourcepub fn on_prepend<E>(
&self,
listener: impl Fn(&E) -> <E as Event>::Output + Send + Sync + 'static,
) -> Result<EffectHandle, Error>where
E: Event,
pub fn on_prepend<E>(
&self,
listener: impl Fn(&E) -> <E as Event>::Output + Send + Sync + 'static,
) -> Result<EffectHandle, Error>where
E: Event,
Registers a listener that runs before the ones registered so far.
Sourcepub fn on_async<E, F, Fut>(&self, listener: F) -> Result<EffectHandle, Error>
pub fn on_async<E, F, Fut>(&self, listener: F) -> Result<EffectHandle, Error>
Registers an asynchronous listener. emit and bail start it
without waiting (a panic is logged); serial and parallel await it.
Sourcepub fn once<E>(
&self,
listener: impl FnOnce(&E) -> <E as Event>::Output + Send + 'static,
) -> Result<EffectHandle, Error>
pub fn once<E>( &self, listener: impl FnOnce(&E) -> <E as Event>::Output + Send + 'static, ) -> Result<EffectHandle, Error>
Registers a listener that runs at most once.
Sourcepub fn emit<E>(&self, event: &E)where
E: Event,
pub fn emit<E>(&self, event: &E)where
E: Event,
Calls every listener; asynchronous ones are started, not awaited. A panicking listener is logged and the rest still run.
Sourcepub fn bail<E>(&self, event: &E) -> Option<<E as Event>::Output>where
E: Event,
pub fn bail<E>(&self, event: &E) -> Option<<E as Event>::Output>where
E: Event,
Calls synchronous listeners until one returns a bailing result; asynchronous ones are started, not awaited. A panicking listener is logged and counts as not bailing.
Sourcepub async fn serial<E>(
&self,
event: &E,
) -> Result<Option<<E as Event>::Output>, Error>where
E: Event,
pub async fn serial<E>(
&self,
event: &E,
) -> Result<Option<<E as Event>::Output>, Error>where
E: Event,
Calls listeners one after another, awaiting each, until one bails. A panicking listener stops the dispatch with its panic as the error.
Sourcepub async fn parallel<E>(&self, event: &E) -> Result<(), AggregateError>where
E: Event,
pub async fn parallel<E>(&self, event: &E) -> Result<(), AggregateError>where
E: Event,
Calls all listeners concurrently and collects their failures.
Sourcepub fn listener_count<E>(&self) -> usizewhere
E: Event,
pub fn listener_count<E>(&self) -> usizewhere
E: Event,
Number of listeners currently registered for E.
Sourcepub fn on_update<C>(
&self,
accept: impl Fn(&C) -> bool + Send + Sync + 'static,
) -> Result<EffectHandle, Error>where
C: Any,
pub fn on_update<C>(
&self,
accept: impl Fn(&C) -> bool + Send + Sync + 'static,
) -> Result<EffectHandle, Error>where
C: Any,
Offers configuration updates of the current fiber to accept before
restarting it. Returning true takes the update over (no restart).
The hook sees the decoded configuration; it is skipped if C does
not match the plugin’s configuration type.
Sourcepub fn on_update_with<C>(
&self,
accept: impl Fn(&C) -> Option<Pin<Box<dyn Future<Output = Result<(), Error>> + Send>>> + Send + Sync + 'static,
) -> Result<EffectHandle, Error>where
C: Any,
pub fn on_update_with<C>(
&self,
accept: impl Fn(&C) -> Option<Pin<Box<dyn Future<Output = Result<(), Error>> + Send>>> + Send + Sync + 'static,
) -> Result<EffectHandle, Error>where
C: Any,
Like Context::on_update; a hook taking the update over returns
the future that update resolves with.
Sourcepub fn on_config(
&self,
hook: Arc<dyn Fn(&Fiber, Value, &dyn Fn(Value) -> Result<Arc<dyn Any + Send + Sync>, Error>) -> Result<Arc<dyn Any + Send + Sync>, Error> + Send + Sync>,
) -> Result<EffectHandle, Error>
pub fn on_config( &self, hook: Arc<dyn Fn(&Fiber, Value, &dyn Fn(Value) -> Result<Arc<dyn Any + Send + Sync>, Error>) -> Result<Arc<dyn Any + Send + Sync>, Error> + Send + Sync>, ) -> Result<EffectHandle, Error>
Registers a configuration resolution hook for every fiber of the root.
Sourcepub fn checkpoint(&self) -> Result<(), Interrupted>
pub fn checkpoint(&self) -> Result<(), Interrupted>
An iteration boundary of the fiber’s own load (L-Divert): fails with
Interrupted once the load has been superseded or the fiber retired.
Returning that error from apply is not a failure.
Sourcepub fn logger(&self) -> Logger
pub fn logger(&self) -> Logger
The logger of this context: named by intercept("logger", { name })
or after the fiber’s plugin.
pub fn logger_named(&self, name: impl Into<String>) -> Logger
Sourcepub fn add_exporter(
&self,
exporter: Arc<dyn Exporter>,
) -> Result<EffectHandle, Error>
pub fn add_exporter( &self, exporter: Arc<dyn Exporter>, ) -> Result<EffectHandle, Error>
Registers an exporter as an effect of the current fiber.
Sourcepub fn log_buffer(&self) -> Vec<Message>
pub fn log_buffer(&self) -> Vec<Message>
The most recent messages (bounded ring buffer, oldest first).
pub fn set_log_buffer_size(&self, size: usize)
Sourcepub fn plugin<P>(&self, config: <P as Plugin>::Config) -> Result<Fiber, Error>
pub fn plugin<P>(&self, config: <P as Plugin>::Config) -> Result<Fiber, Error>
Instantiates a typed plugin as a child fiber of the current fiber.
Sourcepub fn plugin_value<P>(&self, config: Value) -> Result<Fiber, Error>where
P: Plugin,
pub fn plugin_value<P>(&self, config: Value) -> Result<Fiber, Error>where
P: Plugin,
Instantiates a typed plugin from a raw configuration value.
Sourcepub fn plugin_def(&self, def: &PluginDef, config: Value) -> Result<Fiber, Error>
pub fn plugin_def(&self, def: &PluginDef, config: Value) -> Result<Fiber, Error>
Instantiates a plugin definition (O-Insert). The instantiation is an effect of the current fiber, whose inverse retires the new fiber.
Sourcepub fn inject<F, Fut>(
&self,
inject: impl Into<Inject>,
apply: F,
) -> Result<Fiber, Error>
pub fn inject<F, Fut>( &self, inject: impl Into<Inject>, apply: F, ) -> Result<Fiber, Error>
Instantiates an anonymous closure plugin with the given dependencies.
pub fn registry(&self) -> Registry
Sourcepub fn provide<S>(&self, value: S) -> Result<EffectHandle, Error>where
S: Service,
pub fn provide<S>(&self, value: S) -> Result<EffectHandle, Error>where
S: Service,
Provides a service in this context’s realm, as an effect of the current fiber. One realm holds at most one binding per key.
pub fn provide_arc<S>(&self, value: Arc<S>) -> Result<EffectHandle, Error>where
S: Service,
Sourcepub fn provide_as<T>(
&self,
key: impl Into<Key>,
value: T,
) -> Result<EffectHandle, Error>
pub fn provide_as<T>( &self, key: impl Into<Key>, value: T, ) -> Result<EffectHandle, Error>
Provides any value under an explicit key.
pub fn provide_arc_as<T>( &self, key: impl Into<Key>, value: Arc<T>, ) -> Result<EffectHandle, Error>
Sourcepub fn provide_checked<T>(
&self,
key: impl Into<Key>,
value: Arc<T>,
check: Option<Arc<dyn Fn(&[Value]) -> bool + Send + Sync>>,
) -> Result<EffectHandle, Error>
pub fn provide_checked<T>( &self, key: impl Into<Key>, value: Arc<T>, check: Option<Arc<dyn Fn(&[Value]) -> bool + Send + Sync>>, ) -> Result<EffectHandle, Error>
Provides a value whose availability additionally depends on check,
evaluated for each consumer context. The predicate runs under the
runtime lock and must not call into the runtime.
Sourcepub fn provide_serialized_as<T>(
&self,
key: impl Into<Key>,
value: T,
) -> Result<EffectHandle, Error>
pub fn provide_serialized_as<T>( &self, key: impl Into<Key>, value: T, ) -> Result<EffectHandle, Error>
Provides a value that expressions and tooling can read as JSON.
Sourcepub fn migrate_binding(&self, key: &str, from: RealmId, to: RealmId) -> bool
pub fn migrate_binding(&self, key: &str, from: RealmId, to: RealmId) -> bool
Moves the live binding of key from realm from to realm to, if
to is free. The binding keeps its identity, so consumers that
committed to it are not restarted. Returns whether it moved.
Sourcepub fn refresh_consumers(&self, key: &str, realm: RealmId)
pub fn refresh_consumers(&self, key: &str, realm: RealmId)
Re-resolves every fiber that declares key and resolves it to realm
(after isolation tables changed under live fibers).
Sourcepub fn bindings(&self, key: &str) -> Vec<(RealmId, ImplId)>
pub fn bindings(&self, key: &str) -> Vec<(RealmId, ImplId)>
The live bindings of key: each realm with the binding it holds.
Sourcepub fn binding_provider(&self, key: &str, realm: RealmId) -> Option<Context>
pub fn binding_provider(&self, key: &str, realm: RealmId) -> Option<Context>
The context that provided the live binding of key in realm.
Sourcepub fn get<S>(&self) -> Result<Svc<S>, AccessError>where
S: Service,
pub fn get<S>(&self) -> Result<Svc<S>, AccessError>where
S: Service,
Checked access (Algorithm 6): resolves through committed views.
pub fn get_as<T>(&self, key: impl Into<Key>) -> Result<Svc<T>, AccessError>
Sourcepub fn view(&self, key: impl Into<Key>) -> Result<Value, AccessError>
pub fn view(&self, key: impl Into<Key>) -> Result<Value, AccessError>
Checked access to the JSON view of a service (see
Context::provide_serialized_as; JSON values are their own view).
Sourcepub fn live<S>(&self) -> Option<Svc<S>>where
S: Service,
pub fn live<S>(&self) -> Option<Svc<S>>where
S: Service,
Reflective access to the live store: the current binding of the realm, if its provider is active. Never fails for undeclared keys.
pub fn live_as<T>(&self, key: impl Into<Key>) -> Option<Svc<T>>
Trait Implementations§
Auto Trait Implementations§
impl<D> !RefUnwindSafe for Injected<D>
impl<D> !UnwindSafe for Injected<D>
impl<D> Forget for Injected<D>
impl<D> Freeze for Injected<D>
impl<D> Move for Injected<D>
impl<D> Send for Injected<D>
impl<D> Sync for Injected<D>
impl<D> Unpin for Injected<D>
impl<D> UnsafeUnpin for Injected<D>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more