Crate this_state

Source
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.
StateFuture
A future that completes when the state matches the given predicate. This is returned by State::wait_for.
StateRef
A reference to the current state, returned by State::get_ref. It wraps a RwLockReadGuard and can be used to avoid cloning the state.
UpdateOnChangeError
Error returned by State::set_on_change if there are multiple references to the state.