Struct loole::Sender

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

The sending half of a channel.

Implementations§

source§

impl<T> Sender<T>

source

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.

source

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.

source

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.

source

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.

source

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.

source

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

Returns true if the two senders belong to the same channel, and false otherwise.

source

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.

source

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

Returns the capacity of the channel, if it is bounded. Otherwise, returns None.

source

pub fn is_empty(&self) -> bool

Returns true if the channel is empty.

Note: Zero-capacity channels are always empty.

source

pub fn is_full(&self) -> bool

Returns true if the channel is full.

Note: Zero-capacity channels are always full.

source

pub fn close(&self) -> bool

Closes the channel.

Returns true only if this call actively closed the channel, which was previously open.

The remaining messages can still be received.

source

pub fn is_closed(&self) -> bool

Returns true if the channel is closed.

Trait Implementations§

source§

impl<T> Clone for Sender<T>

source§

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)

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> Drop for Sender<T>

source§

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 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> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

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,

§

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>,

§

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>,

§

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.