tokio::io

Function sink

Source
pub fn sink() -> Sink
Available on crate feature io-util only.
Expand description

Creates an instance of an async writer which will successfully consume all data.

All calls to poll_write on the returned instance will return Poll::Ready(Ok(buf.len())) and the contents of the buffer will not be inspected.

This is an asynchronous version of std::io::sink.

ยงExamples

use tokio::io::{self, AsyncWriteExt};

#[tokio::main]
async fn main() -> io::Result<()> {
    let buffer = vec![1, 2, 3, 5, 8];
    let num_bytes = io::sink().write(&buffer).await?;
    assert_eq!(num_bytes, 5);
    Ok(())
}