pub struct Ref<'a, T: Send + Sync + 'static> { /* private fields */ }Expand description
A reference to the value inside the channel.
Unlike a lock guard, a Ref never blocks a sender. It keeps the value it
points to, and every value replaced since, allocated until it is dropped,
so keep it short. It must be dropped on the thread that took it: it is
not Send.
Implementations§
Source§impl<T: Send + Sync + 'static> Ref<'_, T>
impl<T: Send + Sync + 'static> Ref<'_, T>
Sourcepub fn has_changed(&self) -> bool
pub fn has_changed(&self) -> bool
Whether the borrowed value is considered changed since it was last marked seen.
Unlike Receiver::has_changed, this does not fail when the channel
is closed. For a borrow taken from the Sender it is always
false.
use nuclei::sync::watch;
let (tx, mut rx) = watch::channel("hello");
tx.send("goodbye").unwrap();
assert!(!tx.borrow().has_changed());
drop(tx);
assert!(rx.borrow().has_changed());
assert!(rx.borrow_and_update().has_changed());
assert!(!rx.borrow().has_changed());Trait Implementations§
impl<T: Send + Sync + 'static> Sync for Ref<'_, T>
Auto Trait Implementations§
impl<'a, T> !Send for Ref<'a, T>
impl<'a, T> Freeze for Ref<'a, T>
impl<'a, T> RefUnwindSafe for Ref<'a, T>where
T: RefUnwindSafe,
impl<'a, T> Unpin for Ref<'a, T>
impl<'a, T> UnsafeUnpin for Ref<'a, T>
impl<'a, T> UnwindSafe for Ref<'a, T>where
T: RefUnwindSafe,
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