pub struct Watchable<T> { /* private fields */ }
Expand description
A wrapper around a value that notifies Watcher
s when the value is modified.
Only the most recent value is available to any observer, but the observer is guaranteed to be notified of the most recent value.
Implementations§
Source§impl<T: Clone + Eq> Watchable<T>
impl<T: Clone + Eq> Watchable<T>
Sourcepub fn set(&self, value: T) -> Result<T, T>
pub fn set(&self, value: T) -> Result<T, T>
Sets a new value.
Returns Ok(previous_value)
if the value was different from the one set, or
returns the provided value back as Err(value)
if the value didn’t change.
Watchers are only notified if the value changed.
Sourcepub fn has_watchers(&self) -> bool
pub fn has_watchers(&self) -> bool
Returns true when there are any watchers actively listening on changes, or false when all watchers have been dropped or none have been created yet.
Trait Implementations§
Auto Trait Implementations§
impl<T> Freeze for Watchable<T>
impl<T> RefUnwindSafe for Watchable<T>
impl<T> Send for Watchable<T>
impl<T> Sync for Watchable<T>
impl<T> Unpin for Watchable<T>
impl<T> UnwindSafe for Watchable<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