Expand description
A library for managing state changes.
§Examples
The examples below use the following state:
#[derive(Clone, Debug, PartialEq)]
enum MyState {
A,
B,
C
}
§Waiting for a state change
let state = State::new(MyState::A);
let state_clone = state.clone();
tokio::spawn(async move {
// do some work
state_clone.set(MyState::B);
// do some more work
state_clone.set(MyState::C);
});
state.wait_for_state(MyState::C).await;
assert_eq!(state.get(), MyState::C);
Structs§
- State
- A thread-safe state, that can be used to share application state globally.
- State
Future - A future that completes when the state matches the given predicate.
This is returned by
State::wait_for
. - State
Ref - A reference to the current state, returned by
State::get_ref
. It wraps aRwLockReadGuard
and can be used to avoid cloning the state. - Update
OnChange Error - Error returned by
State::set_on_change
if there are multiple references to the state.