Trait futures::io::AsyncWrite[][src]

pub trait AsyncWrite {
    pub fn poll_write(
        self: Pin<&mut Self>,
        cx: &mut Context<'_>,
        buf: &[u8]
    ) -> Poll<Result<usize, Error>>;
pub fn poll_flush(
        self: Pin<&mut Self>,
        cx: &mut Context<'_>
    ) -> Poll<Result<(), Error>>;
pub fn poll_close(
        self: Pin<&mut Self>,
        cx: &mut Context<'_>
    ) -> Poll<Result<(), Error>>; pub fn poll_write_vectored(
        self: Pin<&mut Self>,
        cx: &mut Context<'_>,
        bufs: &[IoSlice<'_>]
    ) -> Poll<Result<usize, Error>> { ... } }
[]

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 the writer cannot take more data, rather than blocking the calling thread.

Required methods

pub fn poll_write(
    self: Pin<&mut Self>,
    cx: &mut Context<'_>,
    buf: &[u8]
) -> Poll<Result<usize, Error>>
[src][]

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.

poll_write must try to make progress by flushing the underlying object if that is the only way the underlying object can become writable again.

pub fn poll_flush(
    self: Pin<&mut Self>,
    cx: &mut Context<'_>
) -> Poll<Result<(), Error>>
[src][]

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.

It only makes sense to do anything here if you actually buffer data.

pub fn poll_close(
    self: Pin<&mut Self>,
    cx: &mut Context<'_>
) -> Poll<Result<(), Error>>
[src][]

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

pub fn poll_write_vectored(
    self: Pin<&mut Self>,
    cx: &mut Context<'_>,
    bufs: &[IoSlice<'_>]
) -> Poll<Result<usize, Error>>
[src][]

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 nonempty buffer in bufs, or an empty one if none exists. 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<P> AsyncWrite for Pin<P> where
    P: DerefMut + Unpin,
    <P as Deref>::Target: AsyncWrite
[src]

impl<'_, T> AsyncWrite for &'_ mut T where
    T: AsyncWrite + Unpin + ?Sized
[src]

impl AsyncWrite for Vec<u8, Global>[src]

impl<T> AsyncWrite for Box<T, Global> where
    T: AsyncWrite + Unpin + ?Sized
[src]

Implementors

impl AsyncWrite for Cursor<Box<[u8], Global>>[src]

impl AsyncWrite for Cursor<Vec<u8, Global>>[src]

impl AsyncWrite for Sink[src]

impl<'_> AsyncWrite for Cursor<&'_ mut Vec<u8, Global>>[src]

impl<'_> AsyncWrite for Cursor<&'_ mut [u8]>[src]

impl<A, B> AsyncWrite for Either<A, B> where
    B: AsyncWrite,
    A: AsyncWrite
[src]

impl<R> AsyncWrite for BufReader<R> where
    R: AsyncWrite
[src]

impl<St> AsyncWrite for IntoAsyncRead<St> where
    St: TryStream<Error = Error> + AsyncWrite + Unpin,
    <St as TryStream>::Ok: AsRef<[u8]>, 
[src]

impl<T> AsyncWrite for AllowStdIo<T> where
    T: Write
[src]

impl<W> AsyncWrite for BufWriter<W> where
    W: AsyncWrite
[src]

impl<W> AsyncWrite for WriteHalf<W> where
    W: AsyncWrite
[src]

impl<T: Write> AsyncWrite for Async<T>

impl<T> AsyncWrite for &Async<T> where
    &'a T: Write

impl AsyncWrite for ChildStdin

impl<T: Write + Send + 'static> AsyncWrite for Unblock<T>

impl<T: Write> AsyncWrite for AssertAsync<T>

impl<W: AsyncWrite> AsyncWrite for BufWriter<W>

impl AsyncWrite for Cursor<&mut [u8]>

impl AsyncWrite for Cursor<&mut Vec<u8>>

impl AsyncWrite for Cursor<Vec<u8>>

impl AsyncWrite for Sink

impl<T: AsyncWrite + Unpin> AsyncWrite for WriteHalf<T>

impl<IO> AsyncWrite for TlsStream<IO> where
    IO: AsyncRead + AsyncWrite + Unpin

impl<IO> AsyncWrite for TlsStream<IO> where
    IO: AsyncRead + AsyncWrite + Unpin

impl<T> AsyncWrite for TlsStream<T> where
    T: AsyncRead + AsyncWrite + Unpin

impl<TInner: AsyncWrite> AsyncWrite for BandwidthConnecLogging<TInner>

impl<A, B> AsyncWrite for EitherOutput<A, B> where
    A: AsyncWrite,
    B: AsyncWrite

impl<P> AsyncWrite for SubstreamRef<P> where
    P: Deref,
    P::Target: StreamMuxer

impl AsyncWrite for DummyStream

impl<S> AsyncWrite for DeflateOutput<S> where
    S: AsyncWrite + Unpin

impl<T: AsyncWrite + Unpin> AsyncWrite for NoiseOutput<T>

impl<S: AsyncRead + AsyncWrite + Unpin> AsyncWrite for PlainTextOutput<S>

impl<S: AsyncRead + AsyncWrite> AsyncWrite for PnetOutput<S>

impl AsyncWrite for Connection

impl<TInner> AsyncWrite for Negotiated<TInner> where
    TInner: AsyncWrite + AsyncRead + Unpin

impl<S> AsyncWrite for RwStreamSink<S> where
    S: TryStream + Sink<<S as TryStream>::Ok, Error = Error>,
    <S as TryStream>::Ok: for<'r> From<&'r [u8]>, 

impl AsyncWrite for Stream