Read in async_std::io - Rust (original) (raw)

pub trait Read {
    // Required method
    fn poll_read(
        self: Pin<&mut Self>,
        cx: &mut Context<'_>,
        buf: &mut [u8],
    ) -> Poll<Result<usize, Error>>;

    // Provided method
    fn poll_read_vectored(
        self: Pin<&mut Self>,
        cx: &mut Context<'_>,
        bufs: &mut [IoSliceMut<'_>],
    ) -> Poll<Result<usize, Error>> { ... }
}

Expand description

Read bytes asynchronously.

This trait is analogous to the std::io::Read trait, but integrates with the asynchronous task system. In particular, the poll_readmethod, unlike Read::read, will automatically queue the current task for wakeup and return if data is not yet available, rather than blocking the calling thread.

Source

Attempt to read from the AsyncRead into buf.

On success, returns Poll::Ready(Ok(num_bytes_read)).

If no data is available for reading, the method returnsPoll::Pending and arranges for the current task (viacx.waker().wake_by_ref()) to receive a notification when the object becomes readable or is closed.

§Implementation

This function may not return errors of kind WouldBlock orInterrupted. Implementations must convert WouldBlock intoPoll::Pending and either internally retry or convertInterrupted into another error kind.

Source

Attempt to read from the AsyncRead into bufs using vectored IO operations.

This method is similar to poll_read, but allows data to be read into multiple buffers using a single operation.

On success, returns Poll::Ready(Ok(num_bytes_read)).

If no data is available for reading, the method returnsPoll::Pending and arranges for the current task (viacx.waker().wake_by_ref()) to receive a notification when the object becomes readable or is closed. By default, this method delegates to using poll_read 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 orInterrupted. Implementations must convert WouldBlock intoPoll::Pending and either internally retry or convertInterrupted into another error kind.

Source§

Source§

Source§

Source§

Source§

Source§

Source§

Source§

Source§

Source§

Source§

Source§

Source§

Source§

Source§

Source§

Source§

Source§

Source§

Source§

Source§

Source§

Source§

Source§

Source§

Source§

Source§

Source§

Source§

Source§

Source§

Source§

Source§

Source§

Source§

Source§

Source§

Source§

Source§

Source§

Source§

Source§

Source§