Skip to main content

AsyncWrite

Trait AsyncWrite 

Source
pub trait AsyncWrite {
    // Required methods
    fn poll_write(
        self: Pin<&mut Self>,
        cx: &mut Context<'_>,
        buf: &[u8],
    ) -> Poll<Result<usize>>;
    fn poll_flush(
        self: Pin<&mut Self>,
        cx: &mut Context<'_>,
    ) -> Poll<Result<()>>;
    fn poll_shutdown(
        self: Pin<&mut Self>,
        cx: &mut Context<'_>,
    ) -> Poll<Result<()>>;
}
Expand description

Async write half of a byte stream.

Mirrors std::io::Write but returns Poll for non-blocking use.

§Contract

  • Poll::Ready(Ok(n)) means n bytes from buf[..n] were written.
  • Poll::Pending means the write buffer is full — the waker will be notified when the stream becomes writable.
  • poll_flush ensures all buffered data reaches the OS send buffer.
  • poll_shutdown signals that no more data will be written (TCP FIN).

Required Methods§

Source

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

Attempt to write buf to the stream.

Source

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

Flush any buffered data to the underlying transport.

Source

fn poll_shutdown(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Result<()>>

Initiate graceful shutdown of the write half.

Implementors§