pub struct SnapshotState<T>where
T: Clone + 'static,{ /* private fields */ }Expand description
Cheap copyable mutable view of a state cell.
Ownership lives elsewhere: a composition slot, an OwnedMutableState, or
the runtime for states created with crate::mutableStateOf /
MutableState::with_runtime.
Implementations§
Source§impl<T> MutableState<T>where
T: Clone + 'static,
impl<T> MutableState<T>where
T: Clone + 'static,
Sourcepub fn with_runtime(value: T, runtime: RuntimeHandle) -> MutableState<T>
pub fn with_runtime(value: T, runtime: RuntimeHandle) -> MutableState<T>
Creates a state holding value in runtime. Every write counts as a change, even of an
equal value. Unless a remember owns the state, the runtime keeps it for its own lifetime.
Sourcepub fn is_alive(&self) -> bool
pub fn is_alive(&self) -> bool
Returns true while the state exists. It ends when its owner releases it or its runtime is
dropped.
Sourcepub fn try_with<R>(&self, f: impl FnOnce(&T) -> R) -> Option<R>
pub fn try_with<R>(&self, f: impl FnOnce(&T) -> R) -> Option<R>
Reads the value through f without subscribing the current scope. Returns None if the
state was released or has no readable value.
Sourcepub fn try_value(&self) -> Option<T>
pub fn try_value(&self) -> Option<T>
Returns a copy of the value without subscribing the current scope, or None if the state
was released or has no readable value.
Sourcepub fn try_retain(&self) -> Option<OwnedMutableState<T>>
pub fn try_retain(&self) -> Option<OwnedMutableState<T>>
Returns an OwnedMutableState that keeps this state alive until its last clone is
dropped. Returns None if the state was already released.
Sourcepub fn retain(&self) -> OwnedMutableState<T>
pub fn retain(&self) -> OwnedMutableState<T>
Returns an OwnedMutableState that keeps this state alive until its last clone is
dropped. Panics if the state was released.
Sourcepub fn with<R>(&self, f: impl FnOnce(&T) -> R) -> R
pub fn with<R>(&self, f: impl FnOnce(&T) -> R) -> R
Reads a copy of the value through f and subscribes the current
scope. f may write this state; see Self::read for a read that
borrows instead of copying.
Sourcepub fn read<R>(&self, f: impl FnOnce(&T) -> R) -> R
pub fn read<R>(&self, f: impl FnOnce(&T) -> R) -> R
Reads the value in place through f and subscribes the current
scope. Nothing is cloned, so a read of a large value costs nothing
beyond f; in return f borrows the stored value and must not write
this state.
Sourcepub fn update<R>(&self, f: impl FnOnce(&mut T) -> R) -> R
pub fn update<R>(&self, f: impl FnOnce(&mut T) -> R) -> R
Runs f on a copy of the value and stores the copy, unless f wrote this state itself.
Scopes that read the state are notified if the value changed.
Sourcepub fn replace(&self, value: T)
pub fn replace(&self, value: T)
Stores value and notifies the scopes that read the state, if the state’s equality policy
sees a change. Does nothing if the state was released.
Sourcepub fn value(&self) -> T
pub fn value(&self) -> T
Returns a copy of the value and subscribes the current scope, which recomposes when the value changes. Panics if the state was released.
Sourcepub fn get_non_reactive(&self) -> T
pub fn get_non_reactive(&self) -> T
Returns a copy of the value without subscribing the current scope.
Trait Implementations§
Source§impl<T> Clone for MutableState<T>where
T: Clone + 'static,
impl<T> Clone for MutableState<T>where
T: Clone + 'static,
Source§fn clone(&self) -> MutableState<T>
fn clone(&self) -> MutableState<T>
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreimpl<T> Copy for MutableState<T>where
T: Clone + 'static,
Source§impl<T> Debug for MutableState<T>
impl<T> Debug for MutableState<T>
impl<T> Eq for MutableState<T>where
T: Clone + 'static,
Auto Trait Implementations§
impl<T> Freeze for MutableState<T>
impl<T> RefUnwindSafe for MutableState<T>
impl<T> Send for MutableState<T>
impl<T> Sync for MutableState<T>
impl<T> Unpin for MutableState<T>
impl<T> UnsafeUnpin for MutableState<T>
impl<T> UnwindSafe for MutableState<T>
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
impl<T> ErasedDestructor for Twhere
T: 'static,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more