Struct this_state::State
source · pub struct State<S> { /* private fields */ }Expand description
A thread-safe state, that can be used to share application state globally.
It is similar to a RWLock<S>, but it also allows asynchronous waiting for state changes.
This can be useful to coordinate between different parts of an application.
Implementations§
source§impl<S> State<S>
impl<S> State<S>
sourcepub fn new_with_on_change(
state: S,
on_change: impl Fn(&S, &S) + 'static
) -> Self
pub fn new_with_on_change( state: S, on_change: impl Fn(&S, &S) + 'static ) -> Self
Creates a new state with the given on_change callback.
Notes
The callback is not called when the state is set for the first time, as well as on
the State::update method. You must call the callback manually in these cases.
sourcepub fn get_ref(&self) -> StateRef<'_, S>
pub fn get_ref(&self) -> StateRef<'_, S>
Returns a reference to the current state.
This can be used if the state does not implement Clone or if you want to avoid cloning.
Trait Implementations§
impl<S> Send for State<S>
impl<S> Sync for State<S>
Auto Trait Implementations§
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more