Expand description

A sink for values which are asynchronously accepted, until the target is closed.

Postage channel senders implement Sink:

use postage::mpsc::channel;
use postage::sink::Sink;

#[tokio::main]
async fn main() {
    let (mut tx, rx) = channel(16);
    assert_eq!(Ok(()), tx.send(true).await);
}

Sinks return an error if the channel is closed, and the message cannot be accepted by the receiver:

use postage::mpsc::channel;
use postage::sink::{SendError, Sink};

#[tokio::main]
async fn main() {
    let (mut tx, rx) = channel(16);
    drop(rx);
    assert_eq!(Err(SendError(true)), tx.send(true).await);
}

Note that Sink::send returns an Err type, unlike Stream::recv which returns an option. This is because the failure to send a message sometimes needs to be interpreted as an application error:

use postage::mpsc::channel;
use postage::sink::{SendError, Sink};

#[tokio::main]
async fn main() -> Result<(), SendError<bool>> {
    let (mut tx, rx) = channel(16);
    tx.send(true).await?;
    Ok(())
}

Tasks can ignore send errors by using Result::ok:

use postage::mpsc::channel;
use postage::sink::Sink;

#[tokio::main]
async fn main() {
    let (mut tx, rx) = channel(16);
    tx.send(true).await.ok();
}

Structs

An error type returned by Sink::send, if the sink is closed while a send is in progress.

A future returned by Sink::send, which wraps an item. The item is sent to the sink, or returned if the sink is closed.

Enums

An enum of poll responses that are produced by Sink implementations.

An error type returned by Sink::try_send, when the sink is full, or is closed.

Traits

A sink which can asynchronously accept messages, and at some point may refuse to accept any further messages.