Skip to main content

OwnedMutableState

Struct OwnedMutableState 

Source
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>

Source

pub fn with_runtime(value: T, runtime: RuntimeHandle) -> Self

Creates a reclaimable state owned by this Rust value.

Source

pub fn handle(&self) -> MutableState<T>

Returns a cheap copyable mutable handle to the owned state.

Source

pub fn as_state(&self) -> State<T>

Returns a cheap copyable read-only handle to the owned state.

Methods from Deref<Target = MutableState<T>>§

Source

pub fn is_alive(&self) -> bool

Returns true if the underlying state cell is still alive (not released).

Source

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).

Source

pub fn try_value(&self) -> Option<T>

Like value, but returns None if the state cell has been released.

Source

pub fn as_state(&self) -> State<T>

Source

pub fn try_retain(&self) -> Option<OwnedMutableState<T>>

Upgrades this handle into an owning state value if the cell is still alive.

Source

pub fn retain(&self) -> OwnedMutableState<T>

Upgrades this handle into an owning state value.

Source

pub fn with<R>(&self, f: impl FnOnce(&T) -> R) -> R

Source

pub fn update<R>(&self, f: impl FnOnce(&mut T) -> R) -> R

Source

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.

Source

pub fn set_value(&self, value: T)

Source

pub fn set(&self, value: T)

Source

pub fn value(&self) -> T

Source

pub fn get(&self) -> T

Source

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>

Source§

fn clone(&self) -> OwnedMutableState<T>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<T: Clone + 'static> Deref for OwnedMutableState<T>

Source§

type Target = MutableState<T>

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Self::Target

Dereferences the value.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.