Struct mesh_channel::Sender
source · pub struct Sender<T>(/* private fields */);
Expand description
The sending half of a channel returned by channel
.
Implementations§
source§impl<T: MeshField> Sender<T>
impl<T: MeshField> Sender<T>
sourcepub fn upcast<U: MeshField>(self) -> Sender<U>
pub fn upcast<U: MeshField>(self) -> Sender<U>
Upcasts this sender to one that can send values whose encoding is a
subset of T
’s.
let (send, mut recv) = channel::<Option<mesh_node::message::Message>>();
let send = send.upcast::<Option<(u32, u16)>>();
send.send(None);
send.send(Some((5, 4)));
assert!(block_on(recv.recv()).unwrap().is_none());
assert!(block_on(recv.recv()).unwrap().is_some());
source§impl<T: 'static + Send> Sender<T>
impl<T: 'static + Send> Sender<T>
sourcepub fn send(&self, msg: T)
pub fn send(&self, msg: T)
Sends a message to the associated Receiver<T>
.
Does not return a result, so messages can be silently dropped if the receiver has closed or failed. To detect such conditions, include another sender in the message you send so that the receiving thread can use it to send a response.
let (send, mut recv) = channel();
let (response_send, mut response_recv) = channel::<bool>();
send.send((3, response_send));
let (val, response_send) = recv.recv().await.unwrap();
response_send.send(val == 3);
assert_eq!(response_recv.recv().await.unwrap(), true);
sourcepub fn bridge(self, recv: Receiver<T>)
pub fn bridge(self, recv: Receiver<T>)
Bridges this and recv
together, consuming both self
and recv
. This
makes it so that anything sent to recv
will be directly sent to this
channel’s peer receiver, without a separate relay step. This includes
any data that was previously sent but not yet consumed.
let (outer_send, inner_recv) = channel::<u32>();
let (inner_send, mut outer_recv) = channel::<u32>();
outer_send.send(2);
inner_send.send(1);
inner_send.bridge(inner_recv);
assert_eq!(outer_recv.try_recv().unwrap(), 1);
assert_eq!(outer_recv.try_recv().unwrap(), 2);
Trait Implementations§
source§impl<T> DefaultEncoding for Sender<T>where
T: MeshField,
impl<T> DefaultEncoding for Sender<T>where
T: MeshField,
source§type Encoding = TableEncoder
type Encoding = TableEncoder
The encoding to use for the serialization. Read more
source§impl<T: 'static + Send> RpcSend for Sender<T>
impl<T: 'static + Send> RpcSend for Sender<T>
source§impl<'encoding, T> StructDecodeMetadata<'encoding, Resource> for Sender<T>where
T: MeshField,
impl<'encoding, T> StructDecodeMetadata<'encoding, Resource> for Sender<T>where
T: MeshField,
source§const DECODERS: &'static [ErasedDecoderEntry] = _
const DECODERS: &'static [ErasedDecoderEntry] = _
The list of decoder vtables.
source§impl<T> StructEncodeMetadata<Resource> for Sender<T>where
T: MeshField,
impl<T> StructEncodeMetadata<Resource> for Sender<T>where
T: MeshField,
source§const ENCODERS: &'static [ErasedEncoderEntry] = _
const ENCODERS: &'static [ErasedEncoderEntry] = _
The list of encoder vtables.
source§impl<T> StructMetadata for Sender<T>where
T: MeshField,
impl<T> StructMetadata for Sender<T>where
T: MeshField,
impl<T: MeshField, U: MeshField> Downcast<Sender<U>> for Sender<T>
Auto Trait Implementations§
impl<T> Freeze for Sender<T>
impl<T> !RefUnwindSafe for Sender<T>
impl<T> Send for Sender<T>
impl<T> Sync for Sender<T>
impl<T> Unpin for Sender<T>
impl<T> !UnwindSafe for Sender<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
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<'_>)
Computes the message size, as in
MessageEncode::compute_message_size
.source§fn write_message(self, writer: MessageWriter<'_, '_, Resource>)
fn write_message(self, writer: MessageWriter<'_, '_, Resource>)
Writes the message, as in
MessageEncode::write_message
.source§fn extract(self) -> <T as SerializeMessage>::Concrete
fn extract(self) -> <T as SerializeMessage>::Concrete
Extract the concrete message.