Skip to main content

Sender

Struct Sender 

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

Sends values to the associated Receiver.

Created by channel. Cloning it counts one more sender.

Implementations§

Source§

impl<T> Sender<T>

Source

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

Sends a value, waiting in line for room if the channel is full.

§Errors

A SendError holding the value when the receiver is closed or gone.

§Cancel safety

A dropped future sent nothing and drops its value; it holds no slot.

use nuclei::sync::local::mpsc;

nuclei::runtime::block_on(async {
    let (tx, mut rx) = mpsc::channel(1);
    tx.send(1).await.unwrap();
    assert_eq!(rx.recv().await, Some(1));
});
Source

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

Sends a value at once, or says why it cannot be sent. It never takes a slot ahead of a send or reservation that is waiting.

§Errors

TrySendError::Full if no slot is free or a send is waiting, TrySendError::Closed if the receiver closed or was dropped. Both hold the value back.

Source

pub async fn reserve(&self) -> Result<Permit<'_, T>, SendError<()>>

Waits in line for a slot and reserves it: the send through the Permit never waits and never fails.

§Errors

A SendError when the receiver is closed or gone.

§Cancel safety

A dropped future holds no slot.

Source

pub fn try_reserve(&self) -> Result<Permit<'_, T>, TrySendError<()>>

Reserves a slot at once if one is free and nobody waits.

§Errors

TrySendError::Full if no slot is free or a send is waiting, TrySendError::Closed if the receiver closed or was dropped.

Source

pub async fn closed(&self)

Completes when the receiver has been closed or dropped. Cancel safe; once the channel is closed every call completes at once.

Source

pub fn is_closed(&self) -> bool

Whether the receiver has been closed or dropped.

Source

pub fn same_channel(&self, other: &Self) -> bool

Whether both senders send to the same channel.

Source

pub fn capacity(&self) -> usize

The channel’s current capacity: the slots that are free.

Source

pub fn max_capacity(&self) -> usize

The channel’s maximum capacity: the buffer it was created with.

Trait Implementations§

Source§

impl<T> Clone for Sender<T>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · 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
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more

Auto Trait Implementations§

§

impl<T> !RefUnwindSafe for Sender<T>

§

impl<T> !Send for Sender<T>

§

impl<T> !Sync for Sender<T>

§

impl<T> !UnwindSafe for Sender<T>

§

impl<T> Freeze for Sender<T>

§

impl<T> Unpin for Sender<T>

§

impl<T> UnsafeUnpin 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, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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,

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.