pub struct OwnedMutableState<T: Clone + 'static> { /* private fields */ }Expand description
Owning state handle for reclaimable state cells.
Implementations§
Source§impl<T: Clone + 'static> OwnedMutableState<T>
impl<T: Clone + 'static> OwnedMutableState<T>
Sourcepub fn with_runtime(value: T, runtime: RuntimeHandle) -> Self
pub fn with_runtime(value: T, runtime: RuntimeHandle) -> Self
Creates a state holding value in runtime. The state is released when the last clone of
this handle is dropped. Every write counts as a change, even of an equal value.
Sourcepub fn with_runtime_structural_eq(value: T, runtime: RuntimeHandle) -> Selfwhere
T: PartialEq,
pub fn with_runtime_structural_eq(value: T, runtime: RuntimeHandle) -> Selfwhere
T: PartialEq,
Creates a state holding value in runtime. Writing a value equal to the current one is
not a change.
Sourcepub fn handle(&self) -> MutableState<T>
pub fn handle(&self) -> MutableState<T>
Returns the copyable MutableState handle. It does not keep the state alive.
Methods from Deref<Target = MutableState<T>>§
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 + 'static> Deref for OwnedMutableState<T>
impl<T: Clone + 'static> Deref for OwnedMutableState<T>
Source§impl<T: Clone + 'static> PartialEq for OwnedMutableState<T>
Two owning handles are equal when they hold the same state, as two
MutableState handles are.
impl<T: Clone + 'static> PartialEq for OwnedMutableState<T>
Two owning handles are equal when they hold the same state, as two
MutableState handles are.