pub struct Sender<T> { /* private fields */ }Expand description
The sending half of a channel.
Implementations§
source§impl<T> Sender<T>
impl<T> Sender<T>
sourcepub fn try_send(&self, m: T) -> Result<(), TrySendError<T>>
pub fn try_send(&self, m: T) -> Result<(), TrySendError<T>>
It returns an error if the channel is bounded and full, or if all receivers have been dropped.
If the channel is unbounded, the method behaves the same as the Sender::send method.
This method is useful for avoiding deadlocks. If you are sending a value into a channel and
you are not sure if the channel is full or if all receivers have been dropped, you can use
this method instead of the Sender::send method. If this method returns an error, you can
take appropriate action, such as retrying the send operation later or buffering the value
until you can send it successfully.
sourcepub fn send_async(&self, m: T) -> SendFuture<T> ⓘ
pub fn send_async(&self, m: T) -> SendFuture<T> ⓘ
Asynchronously send a value into the channel, it will return a future that completes when the value has been successfully sent, or when an error has occurred.
The method returns an error if all receivers on the channel have been dropped. If the channel is bounded and is full, the returned future will yield to the async runtime.
sourcepub fn send(&self, m: T) -> Result<(), SendError<T>>
pub fn send(&self, m: T) -> Result<(), SendError<T>>
Sends a value into the channel. Returns an error if all receivers have been dropped, or if the channel is bounded and is full and no receivers are available.
sourcepub fn send_timeout(
&self,
m: T,
timeout: Duration
) -> Result<(), SendTimeoutError<T>>
pub fn send_timeout( &self, m: T, timeout: Duration ) -> Result<(), SendTimeoutError<T>>
Attempts to send a value into the channel.
If all receivers have been dropped or the timeout has expired, this method will return an error. 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.
sourcepub fn send_deadline(
&self,
m: T,
deadline: Instant
) -> Result<(), SendTimeoutError<T>>
pub fn send_deadline( &self, m: T, deadline: Instant ) -> Result<(), SendTimeoutError<T>>
Sends a value into the channel, returning an error if the channel is full and the deadline has passed, or if all receivers have been dropped.
sourcepub fn same_channel(&self, other: &Sender<T>) -> bool
pub fn same_channel(&self, other: &Sender<T>) -> bool
Returns true if the two senders belong to the same channel, and false otherwise.
sourcepub fn len(&self) -> usize
pub fn len(&self) -> usize
Returns the number of messages currently in the channel.
This function is useful for determining how many messages are waiting to be processed by consumers, or for implementing backpressure mechanisms.
sourcepub fn capacity(&self) -> Option<usize>
pub fn capacity(&self) -> Option<usize>
Returns the capacity of the channel, if it is bounded. Otherwise, returns None.
sourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
Returns true if the channel is empty.
Note: Zero-capacity channels are always empty.
sourcepub fn is_full(&self) -> bool
pub fn is_full(&self) -> bool
Returns true if the channel is full.
Note: Zero-capacity channels are always full.
Trait Implementations§
source§impl<T> Clone for Sender<T>
impl<T> Clone for Sender<T>
source§fn clone(&self) -> Self
fn clone(&self) -> Self
Clones this sender. A Sender acts as a handle to the sending end of a channel. The remaining
contents of the channel 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)
fn clone_from(&mut self, source: &Self)
source. Read more