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§
Required Methods§
Sourcefn store_task(&mut self, cx: &mut Context<'_>) -> usize
fn store_task(&mut self, cx: &mut Context<'_>) -> usize
Register a task as needing waking when state changes
Sourcefn remove_task(&mut self, key: usize)
fn remove_task(&mut self, key: usize)
Remove a task from being tracked. Called by ExpectationFuture
when
polled.
Sourcefn notify_state_changed(&self)
fn notify_state_changed(&self)
Notify all pending tasks that state has changed
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.