Struct aldrin::Sender

source ·
pub struct Sender<T: Serialize + ?Sized> { /* private fields */ }
Expand description

The sending end of an established channel.

This type of sender is obtained when a channel has been fully established, either by PendingSender::established or by UnclaimedSender::claim.

Implementations§

source§

impl<T: Serialize + ?Sized> Sender<T>

source

pub fn cast<U: Serialize + ?Sized>(self) -> Sender<U>

Casts the item type to a different type.

source

pub fn poll_send_ready( &mut self, cx: &mut Context<'_> ) -> Poll<Result<(), Error>>

Polls the channel for capacity to send at least 1 item.

source

pub async fn send_ready(&mut self) -> Result<(), Error>

Waits until the channel has capacity to send at least 1 item.

source

pub fn start_send_item(&mut self, item: &T) -> Result<(), Error>

Sends an item on the channel.

This function panics if the channel doesn’t have any capacity left. You must call either send_ready or poll_send_ready before to ensure there is capacity.

source

pub async fn send_item(&mut self, item: &T) -> Result<(), Error>

Sends an item on the channel.

This function will wait until the channel has capacity to send at least 1 item.

source

pub async fn close(&mut self) -> Result<(), Error>

Closes the sender without consuming it.

The will cause the receiving end to receive None after all other items have been received.

§Examples

let (sender, receiver) = handle.create_channel_with_claimed_sender().await?;

let mut receiver = receiver.claim(16).await?;
let mut sender = sender.established().await?;

// Send a couple of items and then close the sender.
sender.send_item(&1).await?;
sender.send_item(&2).await?;
sender.send_item(&3).await?;
sender.close().await?;

// The receiver will receive all items followed by None.
assert_eq!(receiver.next_item().await, Ok(Some(1)));
assert_eq!(receiver.next_item().await, Ok(Some(2)));
assert_eq!(receiver.next_item().await, Ok(Some(3)));
assert_eq!(receiver.next_item().await, Ok(None));
source

pub fn is_closed(&self) -> bool

Returns true if the channel is closed.

source

pub fn poll_closed(&mut self, cx: &mut Context<'_>) -> Poll<()>

Polls whether the channel is closed.

source

pub async fn closed(&mut self)

Completes when the channel is closed.

Trait Implementations§

source§

impl<T: Debug + Serialize + ?Sized> Debug for Sender<T>

source§

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

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

impl<T: Serialize + ?Sized> Sink<&T> for Sender<T>

§

type Error = Error

The type of value produced by the sink when an error occurs.
source§

fn poll_ready( self: Pin<&mut Self>, cx: &mut Context<'_> ) -> Poll<Result<(), Self::Error>>

Attempts to prepare the Sink to receive a value. Read more
source§

fn start_send(self: Pin<&mut Self>, item: &T) -> Result<(), Self::Error>

Begin the process of sending a value to the sink. Each call to this function must be preceded by a successful call to poll_ready which returned Poll::Ready(Ok(())). Read more
source§

fn poll_flush( self: Pin<&mut Self>, _cx: &mut Context<'_> ) -> Poll<Result<(), Self::Error>>

Flush any remaining output from this sink. Read more
source§

fn poll_close( self: Pin<&mut Self>, cx: &mut Context<'_> ) -> Poll<Result<(), Self::Error>>

Flush any remaining output and close this sink, if necessary. Read more
source§

impl<T: Serialize> Sink<T> for Sender<T>

§

type Error = Error

The type of value produced by the sink when an error occurs.
source§

fn poll_ready( self: Pin<&mut Self>, cx: &mut Context<'_> ) -> Poll<Result<(), Self::Error>>

Attempts to prepare the Sink to receive a value. Read more
source§

fn start_send(self: Pin<&mut Self>, item: T) -> Result<(), Self::Error>

Begin the process of sending a value to the sink. Each call to this function must be preceded by a successful call to poll_ready which returned Poll::Ready(Ok(())). Read more
source§

fn poll_flush( self: Pin<&mut Self>, _cx: &mut Context<'_> ) -> Poll<Result<(), Self::Error>>

Flush any remaining output from this sink. Read more
source§

fn poll_close( self: Pin<&mut Self>, cx: &mut Context<'_> ) -> Poll<Result<(), Self::Error>>

Flush any remaining output and close this sink, if necessary. Read more

Auto Trait Implementations§

§

impl<T: ?Sized> Freeze for Sender<T>

§

impl<T> !RefUnwindSafe for Sender<T>

§

impl<T: ?Sized> Send for Sender<T>

§

impl<T: ?Sized> Sync for Sender<T>

§

impl<T: ?Sized> 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, 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.