pub struct MutAppState<T: ?Sized>(/* private fields */);Expand description
A mutable app state.
§Examples
use app_state::{MutAppState, AppStateTrait, stateful};
struct MyState {
counter: u32,
}
#[stateful]
fn func(state: MutAppState<MyState>) {
let mut state = state.get_mut();
state.counter += 1;
}Implementations§
Source§impl<T: 'static + Send> MutAppState<T>
impl<T: 'static + Send> MutAppState<T>
Sourcepub fn get_mut(&self) -> MutAppStateLock<'_, T>
pub fn get_mut(&self) -> MutAppStateLock<'_, T>
Returns reference to inner T.
Source§impl<T: ?Sized> MutAppState<T>
impl<T: ?Sized> MutAppState<T>
Sourcepub fn into_inner(self) -> Arc<Mutex<T>>
pub fn into_inner(self) -> Arc<Mutex<T>>
Unwraps to the internal Arc<T>
Trait Implementations§
Source§impl<T: 'static + Send> AppStateTrait<T, MutAppState<T>> for MutAppState<T>
impl<T: 'static + Send> AppStateTrait<T, MutAppState<T>> for MutAppState<T>
Source§fn init(state: T)
fn init(state: T)
Initializes the state store with the given state.
If the state store has already been initialized, this will overwrite the existing state. Read more
Source§fn init_if_not_exists<F: FnOnce() -> T>(state: F)
fn init_if_not_exists<F: FnOnce() -> T>(state: F)
Initializes the state store with the given state.
If the state store has already been initialized, this will do nothing.
This is useful for initializing the state store with a default state.
If you want to overwrite the existing state, use
init instead. Read moreSource§fn get() -> U
fn get() -> U
Returns a reference to the state.
If the state store has not been initialized, this will panic.
Source§fn try_get() -> Result<U, Box<dyn Error>>
fn try_get() -> Result<U, Box<dyn Error>>
Returns a reference to the state.
If the state store has not been initialized, this will return
Err.Source§fn get_or_insert(val: T) -> U
fn get_or_insert(val: T) -> U
Returns a reference to the state.
Inserts the supplied value if the state store has not been initialized.
Source§fn get_or_insert_with<F: FnOnce() -> T>(f: F) -> U
fn get_or_insert_with<F: FnOnce() -> T>(f: F) -> U
Returns a reference to the state.
Inserts the supplied value if the state store has not been initialized.
Source§fn get_or_insert_default() -> Uwhere
T: Default,
fn get_or_insert_default() -> Uwhere
T: Default,
Returns a reference to the state.
Inserts the default value of
T if the state store has not been initialized.Source§impl<T: ?Sized> Clone for MutAppState<T>
impl<T: ?Sized> Clone for MutAppState<T>
Source§fn clone(&self) -> MutAppState<T>
fn clone(&self) -> MutAppState<T>
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl<T: 'static + Send> CreateAppState<T> for MutAppState<T>
impl<T: 'static + Send> CreateAppState<T> for MutAppState<T>
fn new(state: T) -> MutAppState<T>
Source§impl<T: ?Sized> Deref for MutAppState<T>
impl<T: ?Sized> Deref for MutAppState<T>
Auto Trait Implementations§
impl<T> Freeze for MutAppState<T>where
T: ?Sized,
impl<T> RefUnwindSafe for MutAppState<T>where
T: ?Sized,
impl<T> Send for MutAppState<T>
impl<T> Sync for MutAppState<T>
impl<T> Unpin for MutAppState<T>where
T: ?Sized,
impl<T> UnwindSafe for MutAppState<T>where
T: ?Sized,
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