Skip to main content

LifecycleFuture

Type Alias LifecycleFuture 

Source
pub type LifecycleFuture<'a, T = ()> = Pin<Box<dyn Future<Output = Result<T, ModeActivationError>> + Send + 'a>>;
Expand description

Pinned, boxed, send-able future for Mode::on_activate.

The explicit Pin<Box<dyn Future + Send>> desugaring (rather than async fn in trait) is needed because:

  1. Object safety. Mode has an associated type (Mode::Guard) and is not directly object-safe. The dispatcher stores modes as Arc<dyn DynMode> via the DynMode adapter; the adapter’s on_activate_dyn returns a future whose output is type-erased to Box<dyn Any + Send>.
  2. Send bound. Lifecycle futures may be scheduled across threads (M-async.2 swaps poll_now for runtime-spawned .await); the future itself must be Send so the executor can move it between worker threads.
  3. Explicit lifetime. Modes capture their &self and the ModeContext (owned, Send + 'static); the future’s lifetime is tied to &self via 'a.

The default type parameter T = () lets marker modes write LifecycleFuture<'_> without naming the unit type.

Aliased Type§

pub struct LifecycleFuture<'a, T = ()> { /* private fields */ }