pub trait AsyncWriteExt: AsyncWrite {
    fn write<'a>(&'a mut self, buf: &'a [u8]) -> WriteFuture<'a, Self>Notable traits for WriteFuture<'_, W>impl<W: AsyncWrite + Unpin + ?Sized> Future for WriteFuture<'_, W>    type Output = Result<usize>;
    where
        Self: Unpin
, { ... }
fn write_vectored<'a>(
        &'a mut self,
        bufs: &'a [IoSlice<'a>]
    ) -> WriteVectoredFuture<'a, Self>Notable traits for WriteVectoredFuture<'_, W>impl<W: AsyncWrite + Unpin + ?Sized> Future for WriteVectoredFuture<'_, W> type Output = Result<usize>;
    where
        Self: Unpin
, { ... }
fn write_all<'a>(&'a mut self, buf: &'a [u8]) -> WriteAllFuture<'a, Self>Notable traits for WriteAllFuture<'_, W>impl<W: AsyncWrite + Unpin + ?Sized> Future for WriteAllFuture<'_, W> type Output = Result<()>;
    where
        Self: Unpin
, { ... }
fn flush(&mut self) -> FlushFuture<'_, Self>Notable traits for FlushFuture<'_, W>impl<W: AsyncWrite + Unpin + ?Sized> Future for FlushFuture<'_, W> type Output = Result<()>;
    where
        Self: Unpin
, { ... }
fn close(&mut self) -> CloseFuture<'_, Self>Notable traits for CloseFuture<'_, W>impl<W: AsyncWrite + Unpin + ?Sized> Future for CloseFuture<'_, W> type Output = Result<()>;
    where
        Self: Unpin
, { ... }
fn boxed_writer<'a>(self) -> Pin<Box<dyn AsyncWrite + Send + 'a>>
    where
        Self: Sized + Send + 'a
, { ... } }
Expand description

Extension trait for AsyncWrite.

Provided methods

Writes some bytes into the byte stream.

Returns the number of bytes written from the start of the buffer.

If the return value is Ok(n) then it must be guaranteed that 0 <= n <= buf.len(). A return value of 0 typically means that the underlying object is no longer able to accept bytes and will likely not be able to in the future as well, or that the provided buffer is empty.

Examples
use futures_lite::io::{AsyncWriteExt, BufWriter};

let mut output = Vec::new();
let mut writer = BufWriter::new(&mut output);

let n = writer.write(b"hello").await?;

Like write(), except that it writes a slice of buffers.

Data is copied from each buffer in order, with the final buffer possibly being only partially consumed. This method must behave same as a call to write() with the buffers concatenated would.

Writes an entire buffer into the byte stream.

This method will keep calling write() until there is no more data to be written or an error occurs. It will not return before the entire buffer is successfully written or an error occurs.

Examples
use futures_lite::io::{AsyncWriteExt, BufWriter};

let mut output = Vec::new();
let mut writer = BufWriter::new(&mut output);

let n = writer.write_all(b"hello").await?;

Flushes the stream to ensure that all buffered contents reach their destination.

Examples
use futures_lite::io::{AsyncWriteExt, BufWriter};

let mut output = Vec::new();
let mut writer = BufWriter::new(&mut output);

writer.write_all(b"hello").await?;
writer.flush().await?;

Closes the writer.

Examples
use futures_lite::io::{AsyncWriteExt, BufWriter};

let mut output = Vec::new();
let mut writer = BufWriter::new(&mut output);

writer.close().await?;

Boxes the writer and changes its type to dyn AsyncWrite + Send + 'a.

Examples
use futures_lite::io::AsyncWriteExt;

let writer = Vec::<u8>::new().boxed_writer();

Implementors