Trait futures_util::io::AsyncWriteExt

source ·
pub trait AsyncWriteExt: AsyncWrite {
    // Provided methods
    fn flush(&mut self) -> Flush<'_, Self> 
       where Self: Unpin { ... }
    fn close(&mut self) -> Close<'_, Self> 
       where Self: Unpin { ... }
    fn write_all<'a>(&'a mut self, buf: &'a [u8]) -> WriteAll<'a, Self> 
       where Self: Unpin { ... }
}
Expand description

An extension trait which adds utility methods to AsyncWrite types.

Provided Methods§

source

fn flush(&mut self) -> Flush<'_, Self>
where Self: Unpin,

Creates a future which will entirely flush this AsyncWrite.

§Examples
#![feature(async_await)]
use futures::io::{AllowStdIo, AsyncWriteExt};
use std::io::{BufWriter, Cursor};

let mut output = [0u8; 5];

{
    let mut writer = Cursor::new(&mut output[..]);
    let mut buffered = AllowStdIo::new(BufWriter::new(writer));
    buffered.write_all(&[1, 2]).await?;
    buffered.write_all(&[3, 4]).await?;
    buffered.flush().await?;
}

assert_eq!(output, [1, 2, 3, 4, 0]);
source

fn close(&mut self) -> Close<'_, Self>
where Self: Unpin,

Creates a future which will entirely close this AsyncWrite.

source

fn write_all<'a>(&'a mut self, buf: &'a [u8]) -> WriteAll<'a, Self>
where Self: Unpin,

Write data into this object.

Creates a future that will write the entire contents of the buffer buf into this AsyncWrite.

The returned future will not complete until all the data has been written.

§Examples
#![feature(async_await)]
use futures::io::AsyncWriteExt;
use std::io::Cursor;

let mut writer = Cursor::new([0u8; 5]);

writer.write_all(&[1, 2, 3, 4]).await?;

assert_eq!(writer.into_inner(), [1, 2, 3, 4, 0]);

Object Safety§

This trait is not object safe.

Implementors§