Struct mesh_channel::Receiver
source · pub struct Receiver<T>(/* private fields */);
Expand description
The receiving half of a channel returned by channel
.
Implementations§
source§impl<T: MeshField> Receiver<T>
impl<T: MeshField> Receiver<T>
sourcepub fn upcast<U: MeshField>(self) -> Receiver<U>
pub fn upcast<U: MeshField>(self) -> Receiver<U>
Upcasts this receiver to one that can receive values whose encoding is a
superset of T
’s.
let (send, recv) = channel::<Option<(u32, u16)>>();
let mut recv = recv.upcast::<Option<mesh_node::message::Message>>();
send.send(None);
send.send(Some((5, 4)));
assert!(block_on(recv.recv()).unwrap().is_none());
assert!(block_on(recv.recv()).unwrap().is_some());
sourcepub fn force_downcast<U: MeshField>(self) -> Receiver<U>
pub fn force_downcast<U: MeshField>(self) -> Receiver<U>
Downcasts this receiver to one that can receive values whose encoding is
a subset of T
’s.
Although this is memory safe, it can cause decoding failures if the
associated sender sends values that don’t decode to U
.
source§impl<T: 'static + Send> Receiver<T>
impl<T: 'static + Send> Receiver<T>
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 recv(
&mut self,
) -> impl Future<Output = Result<T, RecvError>> + Unpin + '_
pub fn recv( &mut self, ) -> impl Future<Output = Result<T, RecvError>> + Unpin + '_
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 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.
sourcepub fn bridge(self, send: Sender<T>)
pub fn bridge(self, send: Sender<T>)
See Sender::bridge
.
Trait Implementations§
source§impl<T> DefaultEncoding for Receiver<T>where
T: MeshField,
impl<T> DefaultEncoding for Receiver<T>where
T: MeshField,
source§type Encoding = TableEncoder
type Encoding = TableEncoder
source§impl<T: 'static + Send> FusedStream for Receiver<T>
impl<T: 'static + Send> FusedStream for Receiver<T>
source§fn is_terminated(&self) -> bool
fn is_terminated(&self) -> bool
true
if the stream should no longer be polled.source§impl<T: 'static + Send> Stream for Receiver<T>
impl<T: 'static + Send> Stream for Receiver<T>
Stream
implementation for a channel.
Note that the output item from this throws away the distinction between the channel being closed and the channel failing due to a node error or decoding error. This simplifies most code that does not care about this distinction.
If you need to distinguish between these cases, use Receiver::recv
or
Receiver::poll_recv
.
source§impl<'encoding, T> StructDecodeMetadata<'encoding, Resource> for Receiver<T>where
T: MeshField,
impl<'encoding, T> StructDecodeMetadata<'encoding, Resource> for Receiver<T>where
T: MeshField,
source§const DECODERS: &'static [ErasedDecoderEntry] = _
const DECODERS: &'static [ErasedDecoderEntry] = _
source§impl<T> StructEncodeMetadata<Resource> for Receiver<T>where
T: MeshField,
impl<T> StructEncodeMetadata<Resource> for Receiver<T>where
T: MeshField,
source§const ENCODERS: &'static [ErasedEncoderEntry] = _
const ENCODERS: &'static [ErasedEncoderEntry] = _
source§impl<T> StructMetadata for Receiver<T>where
T: MeshField,
impl<T> StructMetadata for Receiver<T>where
T: MeshField,
impl<T: MeshField, U: MeshField> Downcast<Receiver<U>> for Receiver<T>
Auto Trait Implementations§
impl<T> Freeze for Receiver<T>
impl<T> !RefUnwindSafe for Receiver<T>
impl<T> Send for Receiver<T>
impl<T> Sync for Receiver<T>
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
source§impl<T> Instrument for T
impl<T> Instrument for T
source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
source§impl<T> SerializeMessage for Twhere
T: MeshPayload,
impl<T> SerializeMessage for Twhere
T: MeshPayload,
source§fn compute_message_size(&mut self, sizer: MessageSizer<'_>)
fn compute_message_size(&mut self, sizer: MessageSizer<'_>)
MessageEncode::compute_message_size
.source§fn write_message(self, writer: MessageWriter<'_, '_, Resource>)
fn write_message(self, writer: MessageWriter<'_, '_, Resource>)
MessageEncode::write_message
.