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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.Source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.