Trait futures_util::io::AsyncWriteExt
source · [−]pub trait AsyncWriteExt: AsyncWrite {
fn flush(&mut self) -> Flush<'_, Self>ⓘNotable traits for Flush<'_, W>impl<W> Future for Flush<'_, W>where
W: AsyncWrite + ?Sized + Unpin, type Output = Result<()>;
where
Self: Unpin,
{ ... }
fn close(&mut self) -> Close<'_, Self>ⓘNotable traits for Close<'_, W>impl<W: AsyncWrite + ?Sized + Unpin> Future for Close<'_, W> type Output = Result<()>;
where
Self: Unpin,
{ ... }
fn write<'a>(&'a mut self, buf: &'a [u8]) -> Write<'a, Self>ⓘNotable traits for Write<'_, W>impl<W: AsyncWrite + ?Sized + Unpin> Future for Write<'_, W> type Output = Result<usize>;
where
Self: Unpin,
{ ... }
fn write_vectored<'a>(
&'a mut self,
bufs: &'a [IoSlice<'a>]
) -> WriteVectored<'a, Self>ⓘNotable traits for WriteVectored<'_, W>impl<W: AsyncWrite + ?Sized + Unpin> Future for WriteVectored<'_, W> type Output = Result<usize>;
where
Self: Unpin,
{ ... }
fn write_all<'a>(&'a mut self, buf: &'a [u8]) -> WriteAll<'a, Self>ⓘNotable traits for WriteAll<'_, W>impl<W: AsyncWrite + ?Sized + Unpin> Future for WriteAll<'_, W> type Output = Result<()>;
where
Self: Unpin,
{ ... }
fn into_sink<Item: AsRef<[u8]>>(self) -> IntoSink<Self, Item>
where
Self: Sized,
{ ... }
}
Expand description
An extension trait which adds utility methods to AsyncWrite
types.
Provided Methods
sourcefn flush(&mut self) -> Flush<'_, Self>ⓘNotable traits for Flush<'_, W>impl<W> Future for Flush<'_, W>where
W: AsyncWrite + ?Sized + Unpin, type Output = Result<()>;
where
Self: Unpin,
fn flush(&mut self) -> Flush<'_, Self>ⓘNotable traits for Flush<'_, W>impl<W> Future for Flush<'_, W>where
W: AsyncWrite + ?Sized + Unpin, type Output = Result<()>;
where
Self: Unpin,
W: AsyncWrite + ?Sized + Unpin, type Output = Result<()>;
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]);
sourcefn close(&mut self) -> Close<'_, Self>ⓘNotable traits for Close<'_, W>impl<W: AsyncWrite + ?Sized + Unpin> Future for Close<'_, W> type Output = Result<()>;
where
Self: Unpin,
fn close(&mut self) -> Close<'_, Self>ⓘNotable traits for Close<'_, W>impl<W: AsyncWrite + ?Sized + Unpin> Future for Close<'_, W> type Output = Result<()>;
where
Self: Unpin,
Creates a future which will entirely close this AsyncWrite
.
sourcefn write<'a>(&'a mut self, buf: &'a [u8]) -> Write<'a, Self>ⓘNotable traits for Write<'_, W>impl<W: AsyncWrite + ?Sized + Unpin> Future for Write<'_, W> type Output = Result<usize>;
where
Self: Unpin,
fn write<'a>(&'a mut self, buf: &'a [u8]) -> Write<'a, Self>ⓘNotable traits for Write<'_, W>impl<W: AsyncWrite + ?Sized + Unpin> Future for Write<'_, W> type Output = Result<usize>;
where
Self: Unpin,
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.
sourcefn write_vectored<'a>(
&'a mut self,
bufs: &'a [IoSlice<'a>]
) -> WriteVectored<'a, Self>ⓘNotable traits for WriteVectored<'_, W>impl<W: AsyncWrite + ?Sized + Unpin> Future for WriteVectored<'_, W> type Output = Result<usize>;
where
Self: Unpin,
fn write_vectored<'a>(
&'a mut self,
bufs: &'a [IoSlice<'a>]
) -> WriteVectored<'a, Self>ⓘNotable traits for WriteVectored<'_, W>impl<W: AsyncWrite + ?Sized + Unpin> Future for WriteVectored<'_, W> type Output = Result<usize>;
where
Self: Unpin,
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.
sourcefn write_all<'a>(&'a mut self, buf: &'a [u8]) -> WriteAll<'a, Self>ⓘNotable traits for WriteAll<'_, W>impl<W: AsyncWrite + ?Sized + Unpin> Future for WriteAll<'_, W> type Output = Result<()>;
where
Self: Unpin,
fn write_all<'a>(&'a mut self, buf: &'a [u8]) -> WriteAll<'a, Self>ⓘNotable traits for WriteAll<'_, W>impl<W: AsyncWrite + ?Sized + Unpin> Future for WriteAll<'_, W> type Output = Result<()>;
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
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]);
sourcefn into_sink<Item: AsRef<[u8]>>(self) -> IntoSink<Self, Item>where
Self: Sized,
fn into_sink<Item: AsRef<[u8]>>(self) -> IntoSink<Self, Item>where
Self: Sized,
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]);