pub struct Watchable<T> { /* private fields */ }Expand description
A wrapper around a value that notifies Watchers 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>where
Arc<Shared<T>>: RefUnwindSafe,
impl<T> Send for Watchable<T>
impl<T> Sync for Watchable<T>
impl<T> Unpin for Watchable<T>
impl<T> UnsafeUnpin for Watchable<T>where
Arc<Shared<T>>: UnsafeUnpin,
impl<T> UnwindSafe for Watchable<T>where
Arc<Shared<T>>: UnwindSafe,
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