pub struct State<T> { /* private fields */ }Expand description
A mutable value that notifies the observers that read it. Cloning a State
clones the handle, not the value: all clones share one value.
Implementations§
Source§impl<T: 'static> State<T>
impl<T: 'static> State<T>
Sourcepub fn with<R>(&self, f: impl FnOnce(&T) -> R) -> R
pub fn with<R>(&self, f: impl FnOnce(&T) -> R) -> R
Reads the value by reference and records the read.
Sourcepub fn set_if_changed(&self, value: T)where
T: PartialEq,
pub fn set_if_changed(&self, value: T)where
T: PartialEq,
Replaces the value only if it differs, notifying only on change.
Trait Implementations§
Auto Trait Implementations§
impl<T> !RefUnwindSafe for State<T>
impl<T> !Send for State<T>
impl<T> !Sync for State<T>
impl<T> !UnwindSafe for State<T>
impl<T> Freeze for State<T>
impl<T> Unpin for State<T>
impl<T> UnsafeUnpin for State<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