pub struct Receiver<T> { /* private fields */ }Expand description
Implementations§
Source§impl<T> Receiver<T>
impl<T> Receiver<T>
Sourcepub fn has_changed(&self) -> bool
pub fn has_changed(&self) -> bool
Checks if this channel contains a message that this receiver has not yet seen. The new value is not marked as seen.
Although this method is called has_changed, it does not check new
messages for equality, so this call will return true even if the new
message is equal to the old message.
Sourcepub fn changed(&mut self) -> Notification<'_, T> ⓘ
pub fn changed(&mut self) -> Notification<'_, T> ⓘ
Waits for a change notification, then marks the newest value as seen.
If the newest value in the channel has not yet been marked seen when
this method is called, the method marks that value seen and returns
immediately. If the newest value has already been marked seen, then the
method sleeps until a new message is sent by the Sender connected to
this Receiver, or until the Sender is dropped.
This method returns an error if and only if the Sender is dropped.
Sourcepub fn borrow(&self) -> ValueRef<'_, T>
pub fn borrow(&self) -> ValueRef<'_, T>
Returns a reference to the most recently sent value.
This method does not mark the returned value as seen, so future calls to
Self::changed may return immediately even if you have already seen the
value with a call to borrow.
Care must be taken not to hold a ref, when the sender is setting a new value. This includes not holding a ref across await points and not explicitly yielding control to other fibers while holding a ref.
If the stored type supports internal mutability, it can be changed transparently (without notifying) for the watchers through the reference returned from this function. This is not an intended use case, but it is possible.
Consider using Self::get or Self::get_cloned instead.
Sourcepub fn get(&self) -> Twhere
T: Copy,
pub fn get(&self) -> Twhere
T: Copy,
Returns a copy of the most recently sent value.
This method does not mark the returned value as seen, so future calls to
Self::changed may return immediately even if you have already seen the
value with a call to borrow.
Sourcepub fn get_cloned(&self) -> Twhere
T: Clone,
pub fn get_cloned(&self) -> Twhere
T: Clone,
Returns the most recently sent value cloned.
This method does not mark the returned value as seen, so future calls to
Self::changed may return immediately even if you have already seen the
value with a call to borrow.