[][src]Trait futures_util::io::AsyncWriteExt

pub trait AsyncWriteExt: AsyncWrite {
    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
, { ... }
fn compat_write(self) -> Compat<Self>
    where
        Self: Sized + Unpin
, { ... } }

An extension trait which adds utility methods to AsyncWrite types.

Provided methods

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

Creates a future which will entirely flush this AsyncWrite.

Examples

#![feature(async_await, await_macro)]
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));
    await!(buffered.write_all(&[1, 2]))?;
    await!(buffered.write_all(&[3, 4]))?;
    await!(buffered.flush())?;
}

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

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

Creates a future which will entirely close this AsyncWrite.

Important traits for WriteAll<'_, W>
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, await_macro)]
use futures::io::AsyncWriteExt;
use std::io::Cursor;

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

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

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

Important traits for Compat<R>
fn compat_write(self) -> Compat<Self> where
    Self: Sized + Unpin

Wraps an AsyncWrite in a compatibility wrapper that allows it to be used as a futures 0.1 / tokio-io 0.1 AsyncWrite. Requires the io-compat feature to enable.

Loading content...

Implementors

impl<W: AsyncWrite + ?Sized> AsyncWriteExt for W[src]

Important traits for Flush<'_, W>
fn flush(&mut self) -> Flush<Self> where
    Self: Unpin
[src]

Important traits for Close<'_, W>
fn close(&mut self) -> Close<Self> where
    Self: Unpin
[src]

Important traits for WriteAll<'_, W>
fn write_all<'a>(&'a mut self, buf: &'a [u8]) -> WriteAll<'a, Self> where
    Self: Unpin
[src]

Important traits for Compat<R>
fn compat_write(self) -> Compat<Self> where
    Self: Sized + Unpin
[src]

Loading content...