pub trait ExpectableState: Clone {
    type State: 'static;

    // Required methods
    fn store_task(&mut self, cx: &mut Context<'_>) -> usize;
    fn remove_task(&mut self, key: usize);
    fn notify_state_changed(&self);
    fn read(&self) -> Self::State;
}
Expand description

Trait for objects that allow futures to trigger based on state changes

This trait will commonly be used via the ExpectableStateExt extension trait which provides the convenient when_satisfied function.

You can implement this trait for your own types which implement their own state tracking and notification of futures, or you can use the ExpectationHarness struct in this module which provides a ready to use implementation.

Required Associated Types§

source

type State: 'static

Type of current state we are tracking

Required Methods§

source

fn store_task(&mut self, cx: &mut Context<'_>) -> usize

Register a task as needing waking when state changes

source

fn remove_task(&mut self, key: usize)

Remove a task from being tracked. Called by ExpectationFuture when polled.

source

fn notify_state_changed(&self)

Notify all pending tasks that state has changed

source

fn read(&self) -> Self::State

Read a snapshot of the current State

Object Safety§

This trait is not object safe.

Implementors§

source§

impl<S: Clone + 'static, A> ExpectableState for Expectable<S, A>

§

type State = S