mesh_channel_core

Struct Sender

Source
pub struct Sender<T>(/* private fields */);
Expand description

The sending half of a channel returned by channel.

The sender can be cloned to send messages from multiple threads or processes.

Implementations§

Source§

impl<T> Sender<T>

Source

pub fn send(&self, message: 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);
Source

pub fn is_closed(&self) -> bool

Returns whether the receiving side of the channel is known to be closed (or failed).

This is useful to determine if there is any point in sending more data via this port. Note that even if this returns false messages may still fail to reach the destination, for example if the receiver is closed after this method is called but before the message is consumed.

Source§

impl<T: MeshField> Sender<T>

Source

pub fn bridge(self, receiver: 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> Clone for Sender<T>

Source§

fn clone(&self) -> Self

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<T> Debug for Sender<T>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T> DefaultEncoding for Sender<T>

Source§

type Encoding = PortField

The encoding to use for the serialization. Read more
Source§

impl<T: MeshField> From<Port> for Sender<T>

Source§

fn from(port: Port) -> Self

Converts to this type from the input type.
Source§

impl<T: MeshField> From<Sender<T>> for Port

Source§

fn from(sender: Sender<T>) -> Self

Converts to this type from the input type.

Auto Trait Implementations§

§

impl<T> Freeze for Sender<T>

§

impl<T> !RefUnwindSafe for Sender<T>

§

impl<T> Send for Sender<T>
where T: Send,

§

impl<T> Sync for Sender<T>
where T: Send,

§

impl<T> Unpin for Sender<T>

§

impl<T> !UnwindSafe for Sender<T>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dst: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more