Trait futures_lite::io::AsyncWriteExt

source ·
pub trait AsyncWriteExt: AsyncWrite {
    // Provided methods
    fn write<'a>(&'a mut self, buf: &'a [u8]) -> WriteFuture<'a, Self> 
       where Self: Unpin { ... }
    fn write_vectored<'a>(
        &'a mut self,
        bufs: &'a [IoSlice<'a>],
    ) -> WriteVectoredFuture<'a, Self> 
       where Self: Unpin { ... }
    fn write_all<'a>(&'a mut self, buf: &'a [u8]) -> WriteAllFuture<'a, Self> 
       where Self: Unpin { ... }
    fn flush(&mut self) -> FlushFuture<'_, Self> 
       where Self: Unpin { ... }
    fn close(&mut self) -> CloseFuture<'_, Self> 
       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§

source

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

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?;
source

fn write_vectored<'a>( &'a mut self, bufs: &'a [IoSlice<'a>], ) -> WriteVectoredFuture<'a, Self>
where Self: Unpin,

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.

source

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

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?;
source

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

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?;
source

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

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?;
source

fn boxed_writer<'a>(self) -> Pin<Box<dyn AsyncWrite + Send + 'a>>
where Self: Sized + Send + 'a,

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();

Object Safety§

This trait is not object safe.

Implementors§