pub struct Sender<T> { /* private fields */ }
Expand description

A transmitting end of a channel.

Implementations§

§

impl<T> Sender<T>

pub fn send_async(&self, item: T) -> SendFut<'_, T>

Asynchronously send a value into the channel, returning an error if all receivers have been dropped. If the channel is bounded and is full, the returned future will yield to the async runtime.

In the current implementation, the returned future will not yield to the async runtime if the channel is unbounded. This may change in later versions.

pub fn into_send_async<'a>(self, item: T) -> SendFut<'a, T>

Convert this sender into a future that asynchronously sends a single message into the channel, returning an error if all receivers have been dropped. If the channel is bounded and is full, this future will yield to the async runtime.

In the current implementation, the returned future will not yield to the async runtime if the channel is unbounded. This may change in later versions.

pub fn sink(&self) -> SendSink<'_, T>

Create an asynchronous sink that uses this sender to asynchronously send messages into the channel. The sender will continue to be usable after the sink has been dropped.

In the current implementation, the returned sink will not yield to the async runtime if the channel is unbounded. This may change in later versions.

pub fn into_sink<'a>(self) -> SendSink<'a, T>

Convert this sender into a sink that allows asynchronously sending messages into the channel.

In the current implementation, the returned sink will not yield to the async runtime if the channel is unbounded. This may change in later versions.

§

impl<T> Sender<T>

pub fn try_send(&self, msg: T) -> Result<(), TrySendError<T>>

Attempt to send a value into the channel. If the channel is bounded and full, or all receivers have been dropped, an error is returned. If the channel associated with this sender is unbounded, this method has the same behaviour as Sender::send.

pub fn send(&self, msg: T) -> Result<(), SendError<T>>

Send a value into the channel, returning an error if all receivers have been dropped. If the channel is bounded and is full, this method will block until space is available or all receivers have been dropped. If the channel is unbounded, this method will not block.

pub fn send_deadline( &self, msg: T, deadline: Instant ) -> Result<(), SendTimeoutError<T>>

Send a value into the channel, returning an error if all receivers have been dropped or the deadline has passed. If the channel is bounded and is full, this method will block until space is available, the deadline is reached, or all receivers have been dropped.

pub fn send_timeout( &self, msg: T, dur: Duration ) -> Result<(), SendTimeoutError<T>>

Send a value into the channel, returning an error if all receivers have been dropped or the timeout has expired. If the channel is bounded and is full, this method will block until space is available, the timeout has expired, or all receivers have been dropped.

pub fn is_disconnected(&self) -> bool

Returns true if all receivers for this channel have been dropped.

pub fn is_empty(&self) -> bool

Returns true if the channel is empty. Note: Zero-capacity channels are always empty.

pub fn is_full(&self) -> bool

Returns true if the channel is full. Note: Zero-capacity channels are always full.

pub fn len(&self) -> usize

Returns the number of messages in the channel

pub fn capacity(&self) -> Option<usize>

If the channel is bounded, returns its capacity.

pub fn sender_count(&self) -> usize

Get the number of senders that currently exist, including this one.

pub fn receiver_count(&self) -> usize

Get the number of receivers that currently exist.

Note that this method makes no guarantees that a subsequent send will succeed; it’s possible that between receiver_count() being called and a send(), all open receivers could drop.

pub fn downgrade(&self) -> WeakSender<T>

Creates a WeakSender that does not keep the channel open.

The channel is closed once all Senders are dropped, even if there are still active WeakSenders.

pub fn same_channel(&self, other: &Sender<T>) -> bool

Returns whether the senders are belong to the same channel.

Trait Implementations§

§

impl<T> Clone for Sender<T>

§

fn clone(&self) -> Sender<T>

Clone this sender. Sender acts as a handle to the ending a channel. Remaining channel contents will only be cleaned up when all senders and the receiver have been dropped.

1.0.0 · source§

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

Performs copy-assignment from source. Read more
§

impl<T> Debug for Sender<T>

§

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

Formats the value using the given formatter. Read more
§

impl<T> Drop for Sender<T>

§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

§

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 Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere T: 'a,

§

fn explicit(self, class: Class, tag: u32) -> TaggedParser<'a, Explicit, Self, E>

§

impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere T: 'a,

§

fn implicit( self, class: Class, constructed: bool, tag: u32 ) -> TaggedParser<'a, Implicit, Self, E>

source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

source§

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

Mutably borrows from an owned value. 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 Twhere 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> Same<T> for T

§

type Output = T

Should always be Self
source§

impl<T> ToOwned for Twhere T: Clone,

§

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 Twhere U: Into<T>,

§

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 Twhere U: TryFrom<T>,

§

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.
§

impl<V, T> VZip<V> for Twhere V: MultiLane<T>,

§

fn vzip(self) -> V

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