Skip to main content

Injected

Struct Injected 

Source
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,

Source

pub fn new(ctx: Context) -> Injected<D>

Source

pub fn get<S, I>(&self) -> Result<Svc<S>, AccessError>
where S: Service, D: Has<S, I>,

A declared dependency, read through the committed view: ctx.get::<Database, _>() (the _ is its inferred position in D).

Source

pub fn deps(&self) -> Result<<D as Deps>::Output, AccessError>

All declared dependencies at once.

Source

pub fn context(&self) -> &Context

The underlying (unchecked) context.

Methods from Deref<Target = Context>§

Source

pub fn fiber_id(&self) -> FiberId

Source

pub fn is_root(&self) -> bool

Source

pub fn same_root(&self, other: &Context) -> bool

Whether both contexts belong to the same root.

Source

pub fn ptr_eq(&self, other: &Context) -> bool

Whether both handles denote the very same derived context.

Source

pub fn root(&self) -> Context

The root context.

Source

pub fn isolate(&self, key: impl Into<Key>) -> Context

Derives a context in which key lives in a fresh, private realm.

Source

pub fn isolate_in(&self, key: impl Into<Key>, realm: RealmId) -> Context

Derives a context in which key lives in the given (shared) realm.

Source

pub fn intercept(&self, key: impl Into<Key>, meta: Value) -> Context

Derives a context carrying interception metadata for key.

Source

pub fn extend(&self) -> Context

Derives a context with its own mutable isolation and interception tables (see Overlay).

Source

pub fn extend_with(&self, overlay: &Arc<Overlay>) -> Context

Derives a context backed by a given overlay; several contexts may share one overlay.

Source

pub fn overlay(&self) -> Option<Arc<Overlay>>

The overlay of this very context, if it was made by extend.

Source

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.

Source

pub fn parent_overlay(&self) -> Option<Arc<Overlay>>

The overlay this context is directly derived from, if any.

Source

pub fn tag(&self) -> Option<u64>

The tag of the nearest tagged overlay on the derivation chain.

Source

pub fn is_within(&self, ancestor: &Context) -> bool

Whether this context is derived from ancestor (or is it).

Source

pub fn isolated_keys(&self) -> Vec<Key>

Every key isolated somewhere on this context’s derivation chain.

Source

pub fn realm(&self, key: &str) -> Option<RealmId>

The realm key resolves to from this context, if it has one yet.

Source

pub fn has_isolation(&self, key: &str) -> bool

Whether this context isolates key itself rather than inheriting the root realm.

Source

pub fn intercepts(&self, key: &str) -> Vec<Value>

Interception metadata for key from the outermost context to this one.

Source

pub fn intercept_meta<T>(&self, key: &str) -> T

Interception metadata for key, merged right-biased and deserialized. Malformed metadata yields the default.

Source

pub fn deps<D>(&self) -> Result<<D as Deps>::Output, AccessError>
where D: Deps,

Accesses a tuple of declared services through the committed view.

Source

pub fn effect_sync<F>( &self, label: impl Into<String>, body: F, ) -> Result<EffectHandle, Error>
where F: FnOnce(&EffectScope) -> Result<(), Error>,

Runs a synchronous effect body. If it fails, whatever it collected is disposed and the error is returned.

Source

pub fn effect<F, Fut>( &self, label: impl Into<String>, body: F, ) -> Result<EffectHandle, Error>
where F: FnOnce(EffectScope) -> Fut, Fut: Future<Output = Result<(), Error>> + Send + 'static,

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.

Source

pub fn on_dispose( &self, f: impl FnOnce() + Send + 'static, ) -> Result<EffectHandle, Error>

Registers a plain inverse on the current fiber.

Source

pub fn defer( &self, label: impl Into<String>, disposer: Disposer, ) -> Result<EffectHandle, Error>

Registers an arbitrary inverse on the current fiber.

Source

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.

Source

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.

Source

pub fn on_async<E, F, Fut>(&self, listener: F) -> Result<EffectHandle, Error>
where E: Event, F: Fn(&E) -> Fut + Send + Sync + 'static, Fut: Future<Output = <E as Event>::Output> + Send + 'static,

Registers an asynchronous listener. emit and bail start it without waiting (a panic is logged); serial and parallel await it.

Source

pub fn once<E>( &self, listener: impl FnOnce(&E) -> <E as Event>::Output + Send + 'static, ) -> Result<EffectHandle, Error>
where E: Event, <E as Event>::Output: Default,

Registers a listener that runs at most once.

Source

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.

Source

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.

Source

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.

Source

pub async fn parallel<E>(&self, event: &E) -> Result<(), AggregateError>
where E: Event,

Calls all listeners concurrently and collects their failures.

Source

pub fn listener_count<E>(&self) -> usize
where E: Event,

Number of listeners currently registered for E.

Source

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.

Source

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.

Source

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.

Source

pub fn fiber(&self) -> Fiber

The fiber this context belongs to.

Source

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.

Source

pub fn logger(&self) -> Logger

The logger of this context: named by intercept("logger", { name }) or after the fiber’s plugin.

Source

pub fn logger_named(&self, name: impl Into<String>) -> Logger

Source

pub fn add_exporter( &self, exporter: Arc<dyn Exporter>, ) -> Result<EffectHandle, Error>

Registers an exporter as an effect of the current fiber.

Source

pub fn log_buffer(&self) -> Vec<Message>

The most recent messages (bounded ring buffer, oldest first).

Source

pub fn set_log_buffer_size(&self, size: usize)

Source

pub fn plugin<P>(&self, config: <P as Plugin>::Config) -> Result<Fiber, Error>
where P: Plugin, <P as Plugin>::Config: Serialize,

Instantiates a typed plugin as a child fiber of the current fiber.

Source

pub fn plugin_value<P>(&self, config: Value) -> Result<Fiber, Error>
where P: Plugin,

Instantiates a typed plugin from a raw configuration value.

Source

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.

Source

pub fn inject<F, Fut>( &self, inject: impl Into<Inject>, apply: F, ) -> Result<Fiber, Error>
where F: Fn(Context) -> Fut + Send + Sync + 'static, Fut: Future<Output = Result<(), Error>> + Send + 'static,

Instantiates an anonymous closure plugin with the given dependencies.

Source

pub fn registry(&self) -> Registry

Source

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.

Source

pub fn provide_arc<S>(&self, value: Arc<S>) -> Result<EffectHandle, Error>
where S: Service,

Source

pub fn provide_as<T>( &self, key: impl Into<Key>, value: T, ) -> Result<EffectHandle, Error>
where T: Any + Send + Sync,

Provides any value under an explicit key.

Source

pub fn provide_arc_as<T>( &self, key: impl Into<Key>, value: Arc<T>, ) -> Result<EffectHandle, Error>
where T: Any + Send + Sync,

Source

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>
where T: Any + Send + Sync,

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.

Source

pub fn provide_serialized_as<T>( &self, key: impl Into<Key>, value: T, ) -> Result<EffectHandle, Error>
where T: Any + Send + Sync + Serialize,

Provides a value that expressions and tooling can read as JSON.

Source

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.

Source

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).

Source

pub fn bindings(&self, key: &str) -> Vec<(RealmId, ImplId)>

The live bindings of key: each realm with the binding it holds.

Source

pub fn binding_provider(&self, key: &str, realm: RealmId) -> Option<Context>

The context that provided the live binding of key in realm.

Source

pub fn get<S>(&self) -> Result<Svc<S>, AccessError>
where S: Service,

Checked access (Algorithm 6): resolves through committed views.

Source

pub fn get_as<T>(&self, key: impl Into<Key>) -> Result<Svc<T>, AccessError>
where T: Any + Send + Sync,

Source

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).

Source

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.

Source

pub fn live_as<T>(&self, key: impl Into<Key>) -> Option<Svc<T>>
where T: Any + Send + Sync,

Trait Implementations§

Source§

impl<D> Clone for Injected<D>

Source§

fn clone(&self) -> Injected<D>

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<D> Deref for Injected<D>

Source§

type Target = Context

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Context

Dereferences the value.

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>
where PhantomData<fn() -> D>: Freeze,

§

impl<D> Move for Injected<D>

§

impl<D> Send for Injected<D>
where PhantomData<fn() -> D>: Send,

§

impl<D> Sync for Injected<D>
where PhantomData<fn() -> D>: Sync,

§

impl<D> Unpin for Injected<D>
where PhantomData<fn() -> D>: Unpin,

§

impl<D> UnsafeUnpin for Injected<D>
where PhantomData<fn() -> D>: UnsafeUnpin,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more