[−][src]Trait futures_util::io::AsyncWrite
Write bytes asynchronously.
This trait is analogous to the std::io::Write
trait, but integrates
with the asynchronous task system. In particular, the poll_write
method, unlike Write::write
, will automatically queue the current task
for wakeup and return if data is not yet available, rather than blocking
the calling thread.
Required methods
fn poll_write(
self: Pin<&mut Self>,
cx: &mut Context,
buf: &[u8]
) -> Poll<Result<usize, Error>>
self: Pin<&mut Self>,
cx: &mut Context,
buf: &[u8]
) -> Poll<Result<usize, Error>>
Attempt to write bytes from buf
into the object.
On success, returns Poll::Ready(Ok(num_bytes_written))
.
If the object is not ready for writing, the method returns
Poll::Pending
and arranges for the current task (via
cx.waker().wake_by_ref()
) to receive a notification when the object becomes
writable or is closed.
Implementation
This function may not return errors of kind WouldBlock
or
Interrupted
. Implementations must convert WouldBlock
into
Poll::Pending
and either internally retry or convert
Interrupted
into another error kind.
fn poll_flush(self: Pin<&mut Self>, cx: &mut Context) -> Poll<Result<(), Error>>
Attempt to flush the object, ensuring that any buffered data reach their destination.
On success, returns Poll::Ready(Ok(()))
.
If flushing cannot immediately complete, this method returns
Poll::Pending
and arranges for the current task (via
cx.waker().wake_by_ref()
) to receive a notification when the object can make
progress towards flushing.
Implementation
This function may not return errors of kind WouldBlock
or
Interrupted
. Implementations must convert WouldBlock
into
Poll::Pending
and either internally retry or convert
Interrupted
into another error kind.
fn poll_close(self: Pin<&mut Self>, cx: &mut Context) -> Poll<Result<(), Error>>
Attempt to close the object.
On success, returns Poll::Ready(Ok(()))
.
If closing cannot immediately complete, this function returns
Poll::Pending
and arranges for the current task (via
cx.waker().wake_by_ref()
) to receive a notification when the object can make
progress towards closing.
Implementation
This function may not return errors of kind WouldBlock
or
Interrupted
. Implementations must convert WouldBlock
into
Poll::Pending
and either internally retry or convert
Interrupted
into another error kind.
Provided methods
fn poll_write_vectored(
self: Pin<&mut Self>,
cx: &mut Context,
bufs: &[IoSlice]
) -> Poll<Result<usize, Error>>
self: Pin<&mut Self>,
cx: &mut Context,
bufs: &[IoSlice]
) -> Poll<Result<usize, Error>>
Attempt to write bytes from bufs
into the object using vectored
IO operations.
This method is similar to poll_write
, but allows data from multiple buffers to be written
using a single operation.
On success, returns Poll::Ready(Ok(num_bytes_written))
.
If the object is not ready for writing, the method returns
Poll::Pending
and arranges for the current task (via
cx.waker().wake_by_ref()
) to receive a notification when the object becomes
writable or is closed.
By default, this method delegates to using poll_write
on the first
buffer in bufs
. Objects which support vectored IO should override
this method.
Implementation
This function may not return errors of kind WouldBlock
or
Interrupted
. Implementations must convert WouldBlock
into
Poll::Pending
and either internally retry or convert
Interrupted
into another error kind.
Implementations on Foreign Types
impl AsyncWrite for Vec<u8>
[src]
fn poll_write(
self: Pin<&mut Vec<u8>>,
&mut Context,
buf: &[u8]
) -> Poll<Result<usize, Error>>
[src]
self: Pin<&mut Vec<u8>>,
&mut Context,
buf: &[u8]
) -> Poll<Result<usize, Error>>
fn poll_write_vectored(
self: Pin<&mut Vec<u8>>,
&mut Context,
bufs: &[IoSlice]
) -> Poll<Result<usize, Error>>
[src]
self: Pin<&mut Vec<u8>>,
&mut Context,
bufs: &[IoSlice]
) -> Poll<Result<usize, Error>>
fn poll_flush(self: Pin<&mut Vec<u8>>, &mut Context) -> Poll<Result<(), Error>>
[src]
fn poll_close(
self: Pin<&mut Vec<u8>>,
cx: &mut Context
) -> Poll<Result<(), Error>>
[src]
self: Pin<&mut Vec<u8>>,
cx: &mut Context
) -> Poll<Result<(), Error>>
impl<'_, T> AsyncWrite for &'_ mut T where
T: AsyncWrite + Unpin + ?Sized,
[src]
T: AsyncWrite + Unpin + ?Sized,
fn poll_write(
self: Pin<&mut &'_ mut T>,
cx: &mut Context,
buf: &[u8]
) -> Poll<Result<usize, Error>>
[src]
self: Pin<&mut &'_ mut T>,
cx: &mut Context,
buf: &[u8]
) -> Poll<Result<usize, Error>>
fn poll_write_vectored(
self: Pin<&mut &'_ mut T>,
cx: &mut Context,
bufs: &[IoSlice]
) -> Poll<Result<usize, Error>>
[src]
self: Pin<&mut &'_ mut T>,
cx: &mut Context,
bufs: &[IoSlice]
) -> Poll<Result<usize, Error>>
fn poll_flush(
self: Pin<&mut &'_ mut T>,
cx: &mut Context
) -> Poll<Result<(), Error>>
[src]
self: Pin<&mut &'_ mut T>,
cx: &mut Context
) -> Poll<Result<(), Error>>
fn poll_close(
self: Pin<&mut &'_ mut T>,
cx: &mut Context
) -> Poll<Result<(), Error>>
[src]
self: Pin<&mut &'_ mut T>,
cx: &mut Context
) -> Poll<Result<(), Error>>
impl<P> AsyncWrite for Pin<P> where
P: DerefMut + Unpin,
<P as Deref>::Target: AsyncWrite,
[src]
P: DerefMut + Unpin,
<P as Deref>::Target: AsyncWrite,
fn poll_write(
self: Pin<&mut Pin<P>>,
cx: &mut Context,
buf: &[u8]
) -> Poll<Result<usize, Error>>
[src]
self: Pin<&mut Pin<P>>,
cx: &mut Context,
buf: &[u8]
) -> Poll<Result<usize, Error>>
fn poll_write_vectored(
self: Pin<&mut Pin<P>>,
cx: &mut Context,
bufs: &[IoSlice]
) -> Poll<Result<usize, Error>>
[src]
self: Pin<&mut Pin<P>>,
cx: &mut Context,
bufs: &[IoSlice]
) -> Poll<Result<usize, Error>>
fn poll_flush(
self: Pin<&mut Pin<P>>,
cx: &mut Context
) -> Poll<Result<(), Error>>
[src]
self: Pin<&mut Pin<P>>,
cx: &mut Context
) -> Poll<Result<(), Error>>
fn poll_close(
self: Pin<&mut Pin<P>>,
cx: &mut Context
) -> Poll<Result<(), Error>>
[src]
self: Pin<&mut Pin<P>>,
cx: &mut Context
) -> Poll<Result<(), Error>>
impl<T> AsyncWrite for Box<T> where
T: AsyncWrite + Unpin + ?Sized,
[src]
T: AsyncWrite + Unpin + ?Sized,
fn poll_write(
self: Pin<&mut Box<T>>,
cx: &mut Context,
buf: &[u8]
) -> Poll<Result<usize, Error>>
[src]
self: Pin<&mut Box<T>>,
cx: &mut Context,
buf: &[u8]
) -> Poll<Result<usize, Error>>
fn poll_write_vectored(
self: Pin<&mut Box<T>>,
cx: &mut Context,
bufs: &[IoSlice]
) -> Poll<Result<usize, Error>>
[src]
self: Pin<&mut Box<T>>,
cx: &mut Context,
bufs: &[IoSlice]
) -> Poll<Result<usize, Error>>
fn poll_flush(
self: Pin<&mut Box<T>>,
cx: &mut Context
) -> Poll<Result<(), Error>>
[src]
self: Pin<&mut Box<T>>,
cx: &mut Context
) -> Poll<Result<(), Error>>
fn poll_close(
self: Pin<&mut Box<T>>,
cx: &mut Context
) -> Poll<Result<(), Error>>
[src]
self: Pin<&mut Box<T>>,
cx: &mut Context
) -> Poll<Result<(), Error>>
Implementors
impl AsyncWrite for Cursor<Box<[u8]>>
[src]
fn poll_write(
self: Pin<&mut Self>,
_: &mut Context,
buf: &[u8]
) -> Poll<Result<usize>>
[src]
self: Pin<&mut Self>,
_: &mut Context,
buf: &[u8]
) -> Poll<Result<usize>>
fn poll_write_vectored(
self: Pin<&mut Self>,
_: &mut Context,
bufs: &[IoSlice]
) -> Poll<Result<usize>>
[src]
self: Pin<&mut Self>,
_: &mut Context,
bufs: &[IoSlice]
) -> Poll<Result<usize>>
fn poll_flush(self: Pin<&mut Self>, _: &mut Context) -> Poll<Result<()>>
[src]
fn poll_close(self: Pin<&mut Self>, cx: &mut Context) -> Poll<Result<()>>
[src]
impl AsyncWrite for Cursor<Vec<u8>>
[src]
fn poll_write(
self: Pin<&mut Self>,
_: &mut Context,
buf: &[u8]
) -> Poll<Result<usize>>
[src]
self: Pin<&mut Self>,
_: &mut Context,
buf: &[u8]
) -> Poll<Result<usize>>
fn poll_write_vectored(
self: Pin<&mut Self>,
_: &mut Context,
bufs: &[IoSlice]
) -> Poll<Result<usize>>
[src]
self: Pin<&mut Self>,
_: &mut Context,
bufs: &[IoSlice]
) -> Poll<Result<usize>>
fn poll_flush(self: Pin<&mut Self>, _: &mut Context) -> Poll<Result<()>>
[src]
fn poll_close(self: Pin<&mut Self>, cx: &mut Context) -> Poll<Result<()>>
[src]
impl AsyncWrite for Sink
[src]
fn poll_write(
self: Pin<&mut Self>,
_: &mut Context,
buf: &[u8]
) -> Poll<Result<usize>>
[src]
self: Pin<&mut Self>,
_: &mut Context,
buf: &[u8]
) -> Poll<Result<usize>>
fn poll_write_vectored(
self: Pin<&mut Self>,
_: &mut Context,
bufs: &[IoSlice]
) -> Poll<Result<usize>>
[src]
self: Pin<&mut Self>,
_: &mut Context,
bufs: &[IoSlice]
) -> Poll<Result<usize>>
fn poll_flush(self: Pin<&mut Self>, _: &mut Context) -> Poll<Result<()>>
[src]
fn poll_close(self: Pin<&mut Self>, _: &mut Context) -> Poll<Result<()>>
[src]
impl<'_> AsyncWrite for Cursor<&'_ mut Vec<u8>>
[src]
fn poll_write(
self: Pin<&mut Self>,
_: &mut Context,
buf: &[u8]
) -> Poll<Result<usize>>
[src]
self: Pin<&mut Self>,
_: &mut Context,
buf: &[u8]
) -> Poll<Result<usize>>
fn poll_write_vectored(
self: Pin<&mut Self>,
_: &mut Context,
bufs: &[IoSlice]
) -> Poll<Result<usize>>
[src]
self: Pin<&mut Self>,
_: &mut Context,
bufs: &[IoSlice]
) -> Poll<Result<usize>>
fn poll_flush(self: Pin<&mut Self>, _: &mut Context) -> Poll<Result<()>>
[src]
fn poll_close(self: Pin<&mut Self>, cx: &mut Context) -> Poll<Result<()>>
[src]
impl<'_> AsyncWrite for Cursor<&'_ mut [u8]>
[src]
fn poll_write(
self: Pin<&mut Self>,
_: &mut Context,
buf: &[u8]
) -> Poll<Result<usize>>
[src]
self: Pin<&mut Self>,
_: &mut Context,
buf: &[u8]
) -> Poll<Result<usize>>
fn poll_write_vectored(
self: Pin<&mut Self>,
_: &mut Context,
bufs: &[IoSlice]
) -> Poll<Result<usize>>
[src]
self: Pin<&mut Self>,
_: &mut Context,
bufs: &[IoSlice]
) -> Poll<Result<usize>>
fn poll_flush(self: Pin<&mut Self>, _: &mut Context) -> Poll<Result<()>>
[src]
fn poll_close(self: Pin<&mut Self>, cx: &mut Context) -> Poll<Result<()>>
[src]
impl<A, B> AsyncWrite for Either<A, B> where
A: AsyncWrite,
B: AsyncWrite,
[src]
A: AsyncWrite,
B: AsyncWrite,
fn poll_write(
self: Pin<&mut Self>,
cx: &mut Context,
buf: &[u8]
) -> Poll<Result<usize>>
[src]
self: Pin<&mut Self>,
cx: &mut Context,
buf: &[u8]
) -> Poll<Result<usize>>
fn poll_write_vectored(
self: Pin<&mut Self>,
cx: &mut Context,
bufs: &[IoSlice]
) -> Poll<Result<usize>>
[src]
self: Pin<&mut Self>,
cx: &mut Context,
bufs: &[IoSlice]
) -> Poll<Result<usize>>
fn poll_flush(self: Pin<&mut Self>, cx: &mut Context) -> Poll<Result<()>>
[src]
fn poll_close(self: Pin<&mut Self>, cx: &mut Context) -> Poll<Result<()>>
[src]
impl<St> AsyncWrite for IntoAsyncRead<St> where
St: TryStream<Error = Error> + AsyncWrite + Unpin,
St::Ok: AsRef<[u8]>,
[src]
St: TryStream<Error = Error> + AsyncWrite + Unpin,
St::Ok: AsRef<[u8]>,
fn poll_write(
self: Pin<&mut Self>,
cx: &mut Context,
buf: &[u8]
) -> Poll<Result<usize>>
[src]
self: Pin<&mut Self>,
cx: &mut Context,
buf: &[u8]
) -> Poll<Result<usize>>
fn poll_flush(self: Pin<&mut Self>, cx: &mut Context) -> Poll<Result<()>>
[src]
fn poll_close(self: Pin<&mut Self>, cx: &mut Context) -> Poll<Result<()>>
[src]
impl<T> AsyncWrite for AllowStdIo<T> where
T: Write,
[src]
T: Write,
fn poll_write(
self: Pin<&mut Self>,
_: &mut Context,
buf: &[u8]
) -> Poll<Result<usize>>
[src]
self: Pin<&mut Self>,
_: &mut Context,
buf: &[u8]
) -> Poll<Result<usize>>
fn poll_write_vectored(
self: Pin<&mut Self>,
_: &mut Context,
bufs: &[IoSlice]
) -> Poll<Result<usize>>
[src]
self: Pin<&mut Self>,
_: &mut Context,
bufs: &[IoSlice]
) -> Poll<Result<usize>>
fn poll_flush(self: Pin<&mut Self>, _: &mut Context) -> Poll<Result<()>>
[src]
fn poll_close(self: Pin<&mut Self>, cx: &mut Context) -> Poll<Result<()>>
[src]
impl<W: AsyncWrite> AsyncWrite for BufWriter<W>
[src]
fn poll_write(
self: Pin<&mut Self>,
cx: &mut Context,
buf: &[u8]
) -> Poll<Result<usize>>
[src]
self: Pin<&mut Self>,
cx: &mut Context,
buf: &[u8]
) -> Poll<Result<usize>>
fn poll_write_vectored(
self: Pin<&mut Self>,
cx: &mut Context,
bufs: &[IoSlice]
) -> Poll<Result<usize>>
[src]
self: Pin<&mut Self>,
cx: &mut Context,
bufs: &[IoSlice]
) -> Poll<Result<usize>>
fn poll_flush(self: Pin<&mut Self>, cx: &mut Context) -> Poll<Result<()>>
[src]
fn poll_close(self: Pin<&mut Self>, cx: &mut Context) -> Poll<Result<()>>
[src]
impl<W: AsyncWrite> AsyncWrite for WriteHalf<W>
[src]
fn poll_write(
self: Pin<&mut Self>,
cx: &mut Context,
buf: &[u8]
) -> Poll<Result<usize>>
[src]
self: Pin<&mut Self>,
cx: &mut Context,
buf: &[u8]
) -> Poll<Result<usize>>
fn poll_write_vectored(
self: Pin<&mut Self>,
cx: &mut Context,
bufs: &[IoSlice]
) -> Poll<Result<usize>>
[src]
self: Pin<&mut Self>,
cx: &mut Context,
bufs: &[IoSlice]
) -> Poll<Result<usize>>