pub struct OwnedMutableState<T: Clone + 'static> { /* private fields */ }Expand description
Owning state handle for reclaimable state cells.
Store this when the state lifetime should be tied to a Rust object rather
than the runtime. Use OwnedMutableState::handle to expose a cheap copyable
MutableState to call sites.
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 reclaimable state owned by this Rust value.
Sourcepub fn handle(&self) -> MutableState<T>
pub fn handle(&self) -> MutableState<T>
Returns a cheap copyable mutable handle to the owned state.
Methods from Deref<Target = MutableState<T>>§
Sourcepub fn is_alive(&self) -> bool
pub fn is_alive(&self) -> bool
Returns true if the underlying state cell is still alive (not released).
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>
Like with, but returns None if the state cell has been released.
Use this in frame callbacks, fling animations, and other contexts where the owning composition group may have been disposed (e.g., tab switch).
Sourcepub fn try_value(&self) -> Option<T>
pub fn try_value(&self) -> Option<T>
Like value, but returns None if the state cell has been released.
pub fn as_state(&self) -> State<T>
Sourcepub fn try_retain(&self) -> Option<OwnedMutableState<T>>
pub fn try_retain(&self) -> Option<OwnedMutableState<T>>
Upgrades this handle into an owning state value if the cell is still alive.
Sourcepub fn retain(&self) -> OwnedMutableState<T>
pub fn retain(&self) -> OwnedMutableState<T>
Upgrades this handle into an owning state value.
pub fn with<R>(&self, f: impl FnOnce(&T) -> R) -> R
pub fn update<R>(&self, f: impl FnOnce(&mut T) -> R) -> R
Sourcepub fn replace(&self, value: T)
pub fn replace(&self, value: T)
Sets a new value, silently skipping the write if the state cell was released.
State cells can be released between when a SideEffect closure captures a
MutableState handle and when the side effect actually runs (command
application disposes composition groups, freeing their state slots, before
side effects execute). Using with_typed_opt instead of with_typed
avoids a panic on the stale handle.
pub fn set_value(&self, value: T)
pub fn set(&self, value: T)
pub fn value(&self) -> T
pub fn get(&self) -> T
Sourcepub fn get_non_reactive(&self) -> T
pub fn get_non_reactive(&self) -> T
Gets the current value WITHOUT subscribing to recomposition.
Use this in layout/measure/draw phases to read state without causing the current composition scope to recompose when the state changes.
§When to use
- In modifier nodes (like ScrollNode) during measure()
- In any layout phase code that reads state but shouldn’t trigger recomposition
§When NOT to use
- In composable functions that should update when state changes
- When you want reactive UI updates
Trait Implementations§
Source§impl<T: Clone + Clone + 'static> Clone for OwnedMutableState<T>
impl<T: Clone + Clone + 'static> Clone for OwnedMutableState<T>
Source§fn clone(&self) -> OwnedMutableState<T>
fn clone(&self) -> OwnedMutableState<T>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more