pub struct Mutable<T: 'static>(/* private fields */);Expand description
Local widget state that drives recomposition on every write.
Unlike crate::remember_state (a bare Rc<RefCell<T>> that never requests
a frame), Mutable calls request_frame on set/update so async /
timer / layout-callback mutations reliably re-render. Prefer Signal for
shared/derived state; use Mutable for widget-local state that should
always recompose.
Implementations§
Source§impl<T: 'static> Mutable<T>
impl<T: 'static> Mutable<T>
pub fn new(v: T) -> Self
pub fn get(&self) -> Ref<'_, T>
Sourcepub fn with<R>(&self, f: impl FnOnce(&T) -> R) -> R
pub fn with<R>(&self, f: impl FnOnce(&T) -> R) -> R
Read the current value without holding the borrow across the closure.
pub fn set(&self, v: T)
Sourcepub fn set_neq(&self, v: T)where
T: PartialEq,
pub fn set_neq(&self, v: T)where
T: PartialEq,
Unconditional write + frame request. Prefer set_neq/update_neq for
UI state where equality is cheap - set/update always invalidate.
Like [set], but skips the frame request + signal when the value is
unchanged (T: PartialEq).
pub fn update(&self, f: impl FnOnce(&mut T))
Sourcepub fn update_neq(&self, f: impl FnOnce(&mut T))
pub fn update_neq(&self, f: impl FnOnce(&mut T))
Like [update], but only requests a frame + fires the signal when the
value actually changed (T: PartialEq + Clone).
Sourcepub fn borrow_mut_silent(&self) -> RefMut<'_, T>
pub fn borrow_mut_silent(&self) -> RefMut<'_, T>
Escape hatch when batching many writes. Call request_frame yourself.