pub struct Observer<T> { /* private fields */ }Expand description
An Observer watching for a single message T.
This is similar to the ‘receiver’ end of a channel of length 1, but instead of blocking, the
‘sender’ always overwrites any element in the channel. In particular, any message obtained by
recv or try_recv is guaranteed to be the most
up-to-date at the moment when the message is received.
The channel may be updated when not observed. Receiving a message moves it out of the observer.
An observer can be cheaply cloned (a single Arc::clone) in order to watch for the message
simultaneously from different threads.
Implementations§
Source§impl<T> Observer<T>
impl<T> Observer<T>
Sourcepub fn recv(&self) -> Result<T, RecvError>
pub fn recv(&self) -> Result<T, RecvError>
Receive a message, blocking until a message is available or the channel disconnects.
Sourcepub fn try_recv(&self) -> Result<T, TryRecvError>
pub fn try_recv(&self) -> Result<T, TryRecvError>
Optimistically receive a message if one is available without blocking the current thread.
This operation will fail if there is no message or if there are are no remaining senders.
Trait Implementations§
Auto Trait Implementations§
impl<T> !RefUnwindSafe for Observer<T>
impl<T> !UnwindSafe for Observer<T>
impl<T> Freeze for Observer<T>
impl<T> Send for Observer<T>where
T: Send,
impl<T> Sync for Observer<T>where
T: Send,
impl<T> Unpin for Observer<T>
impl<T> UnsafeUnpin for Observer<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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more