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,
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.
pub fn as_rc(&self) -> Rc<RefCell<T>>
Trait Implementations§
Auto Trait Implementations§
impl<T> !RefUnwindSafe for Mutable<T>
impl<T> !Send for Mutable<T>
impl<T> !Sync for Mutable<T>
impl<T> !UnwindSafe for Mutable<T>
impl<T> Freeze for Mutable<T>
impl<T> Unpin for Mutable<T>
impl<T> UnsafeUnpin for Mutable<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
Mutably borrows from an owned value. Read more