pub struct Receiver<T>(/* private fields */);
Expand description
The receiving half of a channel returned by channel
.
Implementations§
Source§impl<T> Receiver<T>
impl<T> Receiver<T>
Sourcepub fn new() -> Self
pub fn new() -> Self
Creates a new receiver with no senders.
Receives will fail with RecvError::Closed
until Self::sender
is
called.
Sourcepub fn recv(&mut self) -> Recv<'_, T> ⓘ
pub fn recv(&mut self) -> Recv<'_, T> ⓘ
Consumes and returns the next message, waiting until one is available.
Returns immediately when the channel is closed or failed.
let (send, mut recv) = channel();
send.send(5u32);
drop(send);
assert_eq!(recv.recv().await.unwrap(), 5);
assert!(matches!(recv.recv().await.unwrap_err(), RecvError::Closed));
Sourcepub fn try_recv(&mut self) -> Result<T, TryRecvError>
pub fn try_recv(&mut self) -> Result<T, TryRecvError>
Consumes and returns the next message, if there is one.
Otherwise, returns whether the channel is empty, closed, or failed.
let (send, mut recv) = channel();
send.send(5u32);
drop(send);
assert_eq!(recv.try_recv().unwrap(), 5);
assert!(matches!(recv.try_recv().unwrap_err(), TryRecvError::Closed));
Sourcepub fn poll_recv(&mut self, cx: &mut Context<'_>) -> Poll<Result<T, RecvError>>
pub fn poll_recv(&mut self, cx: &mut Context<'_>) -> Poll<Result<T, RecvError>>
Polls for the next message.
If one is available, consumes and returns it. If the channel is closed or failed, fails. Otherwise, registers the current task to wake when a message is available or the channel is closed or fails.
Trait Implementations§
Source§impl<T: MeshField> DefaultEncoding for Receiver<T>
impl<T: MeshField> DefaultEncoding for Receiver<T>
Source§impl<T> FusedStream for Receiver<T>
impl<T> FusedStream for Receiver<T>
Source§fn is_terminated(&self) -> bool
fn is_terminated(&self) -> bool
Returns
true
if the stream should no longer be polled.Source§impl<T> Stream for Receiver<T>
impl<T> Stream for Receiver<T>
Auto Trait Implementations§
impl<T> Freeze for Receiver<T>
impl<T> !RefUnwindSafe for Receiver<T>
impl<T> Send for Receiver<T>where
T: Send,
impl<T> Sync for Receiver<T>where
T: Send,
impl<T> Unpin for Receiver<T>
impl<T> !UnwindSafe for Receiver<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