Skip to main content

AppContext

Struct AppContext 

Source
pub struct AppContext { /* private fields */ }
Expand description

A cheap, cloneable handle to a booted app.

Implementations§

Source§

impl AppContext

Source

pub fn downgrade(&self) -> WeakAppContext

A handle that does not keep the app alive. Providers that need the app after boot (an event bus, a scheduler) hold this instead of an AppContext, so an app dropped without shutdown is still freed.

Source

pub async fn get<T: ?Sized + Send + Sync + 'static>( &self, ) -> Result<Arc<T>, KernelError>

Service locator: resolves the unnamed provider of T from any module, ignoring visibility. Meant for lifecycle hooks, commands and glue code; providers use constructor injection instead.

Source

pub async fn try_get<T: ?Sized + Send + Sync + 'static>(&self) -> Option<Arc<T>>

Like get, but None when no provider of T exists (or it cannot be built; that failure is logged).

Source

pub async fn get_named<T: ?Sized + Send + Sync + 'static>( &self, name: &str, ) -> Result<Arc<T>, KernelError>

Service locator for the provider of T registered under name.

Source

pub async fn get_all<T: ?Sized + Send + Sync + 'static>( &self, ) -> Result<Vec<Arc<T>>, KernelError>

Resolves every multi-binding of T (see ModuleBuilder::multi), in module dependency order.

Source

pub fn multi_count<T: ?Sized + 'static>(&self) -> usize

How many multi-bindings of T the app registers, read from the module graph without resolving any (so a provider’s factory can call it even when those multi-bindings depend on the provider). A module decides with it, once at boot, whether anybody listens: navree-db skips preparing change events in an app with no dyn ChangeObserver.

Source

pub fn contributions<C: Send + Sync + 'static>(&self) -> Vec<Contributed<C>>

Every value of type C contributed by any module, modules in dependency order, then in registration order.

Source

pub fn resolver_for(&self, module: ModuleId) -> Resolver

A resolver with the visibility of module (no request scope).

Source

pub fn request_resolver( &self, module: ModuleId, scope: RequestScope, ) -> Resolver

A resolver with the visibility of module that memoizes request-scoped providers in scope (one scope per HTTP request, job run, command, …).

Source

pub fn commands(&self) -> Vec<CommandSpec>

Every registered command, modules in dependency order.

Source

pub fn command(&self) -> Option<&CommandSpec>

The command this app was booted to run by AppBuilder::run_with_args (or AppBuilder::run), known from the first provider built on; None after a plain boot. Providers check CommandSpec::stdio here before writing to standard output.

Source

pub fn modules(&self) -> Vec<ModuleInfo>

Every module of the app in dependency order (imports first).

Source

pub fn shutdown_token(&self) -> CancellationToken

Cancelled when the app shuts down; long-running tasks should watch it.

Source

pub fn tracker(&self) -> TaskTracker

Spawn background tasks here; graceful shutdown waits for them.

Trait Implementations§

Source§

impl Clone for AppContext

Source§

fn clone(&self) -> Self

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 Debug for AppContext

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

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