[][src]Trait futures::io::AsyncWriteExt

pub trait AsyncWriteExt: AsyncWrite {
    pub fn flush(&mut self) -> Flush<'_, Self>

Notable traits for Flush<'_, W>

impl<'_, W> Future for Flush<'_, W> where
    W: AsyncWrite + Unpin + ?Sized
type Output = Result<(), Error>;

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

Notable traits for Close<'_, W>

impl<'_, W> Future for Close<'_, W> where
    W: Unpin + AsyncWrite + ?Sized
type Output = Result<(), Error>;

    where
        Self: Unpin
, { ... }
pub fn write(&'a mut self, buf: &'a [u8]) -> Write<'a, Self>

Notable traits for Write<'_, W>

impl<'_, W> Future for Write<'_, W> where
    W: Unpin + AsyncWrite + ?Sized
type Output = Result<usize, Error>;

    where
        Self: Unpin
, { ... }
pub fn write_vectored(
        &'a mut self,
        bufs: &'a [IoSlice<'a>]
    ) -> WriteVectored<'a, Self>

Notable traits for WriteVectored<'_, W>

impl<'_, W> Future for WriteVectored<'_, W> where
    W: Unpin + AsyncWrite + ?Sized
type Output = Result<usize, Error>;

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

Notable traits for WriteAll<'_, W>

impl<'_, W> Future for WriteAll<'_, W> where
    W: Unpin + AsyncWrite + ?Sized
type Output = Result<(), Error>;

    where
        Self: Unpin
, { ... }
pub fn write_all_vectored(
        &'a mut self,
        bufs: &'a mut [IoSlice<'a>]
    ) -> WriteAllVectored<'a, Self>

Notable traits for WriteAllVectored<'_, W>

impl<'_, W> Future for WriteAllVectored<'_, W> where
    W: Unpin + AsyncWrite + ?Sized
type Output = Result<(), Error>;

    where
        Self: Unpin
, { ... }
pub fn compat_write(self) -> Compat<Self>

Notable traits for Compat<R>

impl<R> Read for Compat<R> where
    R: Unpin + AsyncRead
impl<W> Write for Compat<W> where
    W: Unpin + AsyncWrite

    where
        Self: Unpin
, { ... }
pub fn into_sink<Item>(self) -> IntoSink<Self, Item>
    where
        Item: AsRef<[u8]>
, { ... } }

An extension trait which adds utility methods to AsyncWrite types.

Provided methods

pub fn flush(&mut self) -> Flush<'_, Self>

Notable traits for Flush<'_, W>

impl<'_, W> Future for Flush<'_, W> where
    W: AsyncWrite + Unpin + ?Sized
type Output = Result<(), Error>;
where
    Self: Unpin
[src]

Creates a future which will entirely flush this AsyncWrite.

Examples

use futures::io::{AllowStdIo, AsyncWriteExt};
use std::io::{BufWriter, Cursor};

let mut output = vec![0u8; 5];

{
    let 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]);

pub fn close(&mut self) -> Close<'_, Self>

Notable traits for Close<'_, W>

impl<'_, W> Future for Close<'_, W> where
    W: Unpin + AsyncWrite + ?Sized
type Output = Result<(), Error>;
where
    Self: Unpin
[src]

Creates a future which will entirely close this AsyncWrite.

pub fn write(&'a mut self, buf: &'a [u8]) -> Write<'a, Self>

Notable traits for Write<'_, W>

impl<'_, W> Future for Write<'_, W> where
    W: Unpin + AsyncWrite + ?Sized
type Output = Result<usize, Error>;
where
    Self: Unpin
[src]

Creates a future which will write bytes from buf into the object.

The returned future will resolve to the number of bytes written once the write operation is completed.

pub fn write_vectored(
    &'a mut self,
    bufs: &'a [IoSlice<'a>]
) -> WriteVectored<'a, Self>

Notable traits for WriteVectored<'_, W>

impl<'_, W> Future for WriteVectored<'_, W> where
    W: Unpin + AsyncWrite + ?Sized
type Output = Result<usize, Error>;
where
    Self: Unpin
[src]

Creates a future which will write bytes from bufs into the object using vectored IO operations.

The returned future will resolve to the number of bytes written once the write operation is completed.

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

Notable traits for WriteAll<'_, W>

impl<'_, W> Future for WriteAll<'_, W> where
    W: Unpin + AsyncWrite + ?Sized
type Output = Result<(), Error>;
where
    Self: Unpin
[src]

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

use futures::io::{AsyncWriteExt, Cursor};

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

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

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

pub fn write_all_vectored(
    &'a mut self,
    bufs: &'a mut [IoSlice<'a>]
) -> WriteAllVectored<'a, Self>

Notable traits for WriteAllVectored<'_, W>

impl<'_, W> Future for WriteAllVectored<'_, W> where
    W: Unpin + AsyncWrite + ?Sized
type Output = Result<(), Error>;
where
    Self: Unpin
[src]

Attempts to write multiple buffers into this writer.

Creates a future that will write the entire contents of bufs into this AsyncWrite using vectored writes.

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

Notes

Unlike io::Write::write_vectored, this takes a mutable reference to a slice of IoSlices, not an immutable one. That's because we need to modify the slice to keep track of the bytes already written.

Once this futures returns, the contents of bufs are unspecified, as this depends on how many calls to write_vectored were necessary. It is best to understand this function as taking ownership of bufs and to not use bufs afterwards. The underlying buffers, to which the IoSlices point (but not the IoSlices themselves), are unchanged and can be reused.

Examples

use futures::io::AsyncWriteExt;
use futures_util::io::Cursor;
use std::io::IoSlice;

let mut writer = Cursor::new(Vec::new());
let bufs = &mut [
    IoSlice::new(&[1]),
    IoSlice::new(&[2, 3]),
    IoSlice::new(&[4, 5, 6]),
];

writer.write_all_vectored(bufs).await?;
// Note: the contents of `bufs` is now unspecified, see the Notes section.

assert_eq!(writer.into_inner(), &[1, 2, 3, 4, 5, 6]);

pub fn compat_write(self) -> Compat<Self>

Notable traits for Compat<R>

impl<R> Read for Compat<R> where
    R: Unpin + AsyncRead
impl<W> Write for Compat<W> where
    W: Unpin + AsyncWrite
where
    Self: Unpin
[src]

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.

pub fn into_sink<Item>(self) -> IntoSink<Self, Item> where
    Item: AsRef<[u8]>, 
[src]

Allow using an AsyncWrite as a Sink<Item: AsRef<[u8]>>.

This adapter produces a sink that will write each value passed to it into the underlying writer.

Note that this function consumes the given writer, returning a wrapped version.

Examples

use futures::io::AsyncWriteExt;
use futures::stream::{self, StreamExt};

let stream = stream::iter(vec![Ok([1, 2, 3]), Ok([4, 5, 6])]);

let mut writer = vec![];

stream.forward((&mut writer).into_sink()).await?;

assert_eq!(writer, vec![1, 2, 3, 4, 5, 6]);
Loading content...

Implementors

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

Loading content...