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ยง
Sourcefn write<'a>(&'a mut self, buf: &'a [u8]) -> WriteFuture<'a, Self> โwhere
Self: Unpin,
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?;
Sourcefn write_vectored<'a>(
&'a mut self,
bufs: &'a [IoSlice<'a>],
) -> WriteVectoredFuture<'a, Self> โwhere
Self: Unpin,
fn write_vectored<'a>(
&'a mut self,
bufs: &'a [IoSlice<'a>],
) -> WriteVectoredFuture<'a, Self> โwhere
Self: Unpin,
Sourcefn write_all<'a>(&'a mut self, buf: &'a [u8]) -> WriteAllFuture<'a, Self> โwhere
Self: Unpin,
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?;
Sourcefn flush(&mut self) -> FlushFuture<'_, Self> โwhere
Self: Unpin,
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?;
Sourcefn close(&mut self) -> CloseFuture<'_, Self> โwhere
Self: Unpin,
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?;
Sourcefn boxed_writer<'a>(self) -> Pin<Box<dyn AsyncWrite + Send + 'a>>
fn boxed_writer<'a>(self) -> Pin<Box<dyn AsyncWrite + 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();
Dyn Compatibilityยง
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.