Skip to main content

Handle

Struct Handle 

Source
pub struct Handle<'m, T: ?Sized, K, C = K> { /* private fields */ }
Expand description

What provide, value, the factory methods and the contribute builder return: a handle on the binding registered by that call, through which its second keys, qualifier, construction bound, readiness check and closure hooks are written.

Implementations§

Source§

impl<'m, T: ?Sized + Send + Sync + 'static, K, C: SingleBinding> Handle<'m, T, K, C>

Source

pub fn also_as<U: ?Sized + Send + Sync + 'static>( self, coerce: impl Fn(Arc<T>) -> Arc<U> + Send + Sync + 'static, ) -> Handle<'m, T, C, C>

A second key under another type, reaching the same object: .also_as::<dyn Cache>(|a| a). The closure’s return is where Arc<T> unsizes to Arc<U>; a T that does not implement the trait fails to compile there.

Source

pub fn qualified<Q: 'static>(self) -> Handle<'m, T, C, C>

Qualifies every key of the binding, its also_as keys included, with Q. A second call replaces the first qualifier.

Source§

impl<'m, T: ?Sized, K, C: HookHost> Handle<'m, T, K, C>

Source

pub fn ready<Args, F, E>( self, check: F, ) -> Handle<'m, T, ReadyItem<Open, Open>, C>
where F: Factory<Args, Output = Result<(), E>>, E: Into<BoxError> + Send + 'static,

A readiness check, run right after the binding is constructed and before anything that depends on it. A check that writes no bound takes construct_timeout as its attempt bound when a Timer exists (§9.3). One check per binding; a second is a wiring error.

.retries(..) counts attempts after the first, zero unless written; .backoff(..) is the wait between attempts, zero unless written.

Source

pub fn on_init<Args, F, E>(self, hook: F) -> Handle<'m, T, HookItem<Open>, C>
where F: Factory<Args, Output = Result<(), E>>, E: Into<BoxError> + Send + 'static,

An init hook, run once every singleton is built and checked, in connect order. Its Err fails connect as ConnectError::Hook.

Source

pub fn on_destroy<Args, F>(self, hook: F) -> Handle<'m, T, HookItem<Open>, C>
where F: Factory<Args, Output = ()>,

Runs after the drain, in reverse connect order.

Source

pub fn before_shutdown<Args, F>( self, hook: F, ) -> Handle<'m, T, HookItem<Open>, C>
where F: ShutdownFactory<Args>,

Runs while the app still serves, before stop-accepting, with the shutdown’s signal.

Source

pub fn on_shutdown<Args, F>(self, hook: F) -> Handle<'m, T, HookItem<Open>, C>
where F: ShutdownFactory<Args>,

Runs last in the shutdown sequence, after the sockets close, with the shutdown’s signal.

Source§

impl<'m, T: ?Sized, K: Timeout<C>, C> Handle<'m, T, K, C>

Source

pub fn timeout(self, d: Duration) -> Handle<'m, T, K::Next, K::Construction>

Bounds the item written last: the construction directly after the binding is registered, the whole check after .ready(..), the hook after an on_*. Needs a Timer; a wiring error about the bound names this call. A zero duration is refused at wire(): write unbounded for no bound.

Source§

impl<'m, T: ?Sized, K: Unbounded<C>, C> Handle<'m, T, K, C>

Source

pub fn unbounded(self) -> Handle<'m, T, K::Next, K::Construction>

No bound on the item written last; still inside shutdown_timeout at shutdown.

Source§

impl<'m, T: ?Sized, K: AttemptTimeout, C> Handle<'m, T, K, C>

Source

pub fn attempt_timeout(self, d: Duration) -> Handle<'m, T, K::Next, C>

Bounds one attempt of the readiness check; an attempt that times out with retries left is retried like one that returned Err. Needs a Timer; a wiring error about the bound names this call. A zero duration is refused at wire().

Source§

impl<'m, T: ?Sized, W, A, C> Handle<'m, T, ReadyItem<W, A>, C>

Source

pub fn retries(self, n: u32) -> Self

Attempts after the first; the last call wins.

Source

pub fn backoff(self, d: Duration) -> Self

The wait between one attempt’s end and the next, timed by the Timer; the last call wins. A nonzero wait on an app with no Timer is a wiring error naming this call.

Auto Trait Implementations§

§

impl<'m, T, K, C = K> !RefUnwindSafe for Handle<'m, T, K, C>

§

impl<'m, T, K, C = K> !UnwindSafe for Handle<'m, T, K, C>

§

impl<'m, T, K, C> Forget for Handle<'m, T, K, C>
where T: ?Sized,

§

impl<'m, T, K, C> Freeze for Handle<'m, T, K, C>
where PhantomData<fn() -> (PhantomData<T>, K, C)>: Freeze, T: ?Sized,

§

impl<'m, T, K, C> Move for Handle<'m, T, K, C>
where T: ?Sized,

§

impl<'m, T, K, C> Send for Handle<'m, T, K, C>
where PhantomData<fn() -> (PhantomData<T>, K, C)>: Send, T: ?Sized,

§

impl<'m, T, K, C> Sync for Handle<'m, T, K, C>
where PhantomData<fn() -> (PhantomData<T>, K, C)>: Sync, T: ?Sized,

§

impl<'m, T, K, C> Unpin for Handle<'m, T, K, C>
where PhantomData<fn() -> (PhantomData<T>, K, C)>: Unpin, T: ?Sized,

§

impl<'m, T, K, C> UnsafeUnpin for Handle<'m, T, K, C>
where PhantomData<fn() -> (PhantomData<T>, K, C)>: UnsafeUnpin, T: ?Sized,

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