pub trait AsyncRead {
    // 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_read method, 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.

Required Methods§

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

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 returns Poll::Pending and arranges for the current task (via cx.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 or Interrupted. Implementations must convert WouldBlock into Poll::Pending and either internally retry or convert Interrupted into another error kind.

Provided Methods§

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

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 returns Poll::Pending and arranges for the current task (via cx.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 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 AsyncRead for &[u8]

§

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

§

fn poll_read_vectored( self: Pin<&mut &[u8]>, _: &mut Context<'_>, bufs: &mut [IoSliceMut<'_>] ) -> Poll<Result<usize, Error>>

§

impl AsyncRead for Body

§

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

§

impl AsyncRead for BoxedTransport
where BoxedTransport: Unpin,

§

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

§

fn poll_read_vectored( self: Pin<&mut BoxedTransport>, cx: &mut Context<'_>, bufs: &mut [IoSliceMut<'_>] ) -> Poll<Result<usize, Error>>

§

impl AsyncRead for Empty

§

fn poll_read( self: Pin<&mut Empty>, _: &mut Context<'_>, _: &mut [u8] ) -> Poll<Result<usize, Error>>

§

impl AsyncRead for Empty

§

fn poll_read( self: Pin<&mut Empty>, _: &mut Context<'_>, _: &mut [u8] ) -> Poll<Result<usize, Error>>

§

impl AsyncRead for Reader

§

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

§

impl AsyncRead for Repeat

§

fn poll_read( self: Pin<&mut Repeat>, _: &mut Context<'_>, buf: &mut [u8] ) -> Poll<Result<usize, Error>>

§

impl AsyncRead for Repeat

§

fn poll_read( self: Pin<&mut Repeat>, _: &mut Context<'_>, buf: &mut [u8] ) -> Poll<Result<usize, Error>>

§

impl AsyncRead for Synthetic

§

fn poll_read( self: Pin<&mut Synthetic>, _cx: &mut Context<'_>, buf: &mut [u8] ) -> Poll<Result<usize, Error>>

§

impl AsyncRead for TcpStream

§

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

§

impl AsyncRead for UnixStream

§

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

§

impl<'conn, Transport> AsyncRead for ReceivedBody<'conn, Transport>
where Transport: AsyncRead + Unpin + Send + Sync + 'static,

§

fn poll_read( self: Pin<&mut ReceivedBody<'conn, Transport>>, cx: &mut Context<'_>, buf: &mut [u8] ) -> Poll<Result<usize, Error>>

§

impl<P> AsyncRead for Pin<P>
where P: DerefMut + Unpin, <P as Deref>::Target: AsyncRead,

§

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

§

fn poll_read_vectored( self: Pin<&mut Pin<P>>, cx: &mut Context<'_>, bufs: &mut [IoSliceMut<'_>] ) -> Poll<Result<usize, Error>>

§

impl<R1, R2> AsyncRead for Chain<R1, R2>
where R1: AsyncRead, R2: AsyncRead,

§

fn poll_read( self: Pin<&mut Chain<R1, R2>>, cx: &mut Context<'_>, buf: &mut [u8] ) -> Poll<Result<usize, Error>>

§

fn poll_read_vectored( self: Pin<&mut Chain<R1, R2>>, cx: &mut Context<'_>, bufs: &mut [IoSliceMut<'_>] ) -> Poll<Result<usize, Error>>

§

impl<R1, R2> AsyncRead for Chain<R1, R2>
where R1: AsyncRead, R2: AsyncRead,

§

fn poll_read( self: Pin<&mut Chain<R1, R2>>, cx: &mut Context<'_>, buf: &mut [u8] ) -> Poll<Result<usize, Error>>

§

fn poll_read_vectored( self: Pin<&mut Chain<R1, R2>>, cx: &mut Context<'_>, bufs: &mut [IoSliceMut<'_>] ) -> Poll<Result<usize, Error>>

§

impl<R> AsyncRead for BufReader<R>
where R: AsyncRead,

§

fn poll_read( self: Pin<&mut BufReader<R>>, cx: &mut Context<'_>, buf: &mut [u8] ) -> Poll<Result<usize, Error>>

§

fn poll_read_vectored( self: Pin<&mut BufReader<R>>, cx: &mut Context<'_>, bufs: &mut [IoSliceMut<'_>] ) -> Poll<Result<usize, Error>>

§

impl<R> AsyncRead for BufReader<R>
where R: AsyncRead,

§

fn poll_read( self: Pin<&mut BufReader<R>>, cx: &mut Context<'_>, buf: &mut [u8] ) -> Poll<Result<usize, Error>>

§

fn poll_read_vectored( self: Pin<&mut BufReader<R>>, cx: &mut Context<'_>, bufs: &mut [IoSliceMut<'_>] ) -> Poll<Result<usize, Error>>

§

impl<R> AsyncRead for Bytes<R>
where R: AsyncRead,

§

fn poll_read( self: Pin<&mut Bytes<R>>, cx: &mut Context<'_>, buf: &mut [u8] ) -> Poll<Result<usize, Error>>

§

fn poll_read_vectored( self: Pin<&mut Bytes<R>>, cx: &mut Context<'_>, bufs: &mut [IoSliceMut<'_>] ) -> Poll<Result<usize, Error>>

§

impl<R> AsyncRead for Bytes<R>
where R: AsyncRead,

§

fn poll_read( self: Pin<&mut Bytes<R>>, cx: &mut Context<'_>, buf: &mut [u8] ) -> Poll<Result<usize, Error>>

§

fn poll_read_vectored( self: Pin<&mut Bytes<R>>, cx: &mut Context<'_>, bufs: &mut [IoSliceMut<'_>] ) -> Poll<Result<usize, Error>>

§

impl<R> AsyncRead for Take<R>
where R: AsyncRead,

§

fn poll_read( self: Pin<&mut Take<R>>, cx: &mut Context<'_>, buf: &mut [u8] ) -> Poll<Result<usize, Error>>

§

impl<R> AsyncRead for Take<R>
where R: AsyncRead,

§

fn poll_read( self: Pin<&mut Take<R>>, cx: &mut Context<'_>, buf: &mut [u8] ) -> Poll<Result<usize, Error>>

§

impl<T> AsyncRead for &Async<T>
where &'a T: for<'a> Read,

§

fn poll_read( self: Pin<&mut &Async<T>>, cx: &mut Context<'_>, buf: &mut [u8] ) -> Poll<Result<usize, Error>>

§

fn poll_read_vectored( self: Pin<&mut &Async<T>>, cx: &mut Context<'_>, bufs: &mut [IoSliceMut<'_>] ) -> Poll<Result<usize, Error>>

§

impl<T> AsyncRead for &Async<T>
where &'a T: for<'a> Read,

§

fn poll_read( self: Pin<&mut &Async<T>>, cx: &mut Context<'_>, buf: &mut [u8] ) -> Poll<Result<usize, Error>>

§

fn poll_read_vectored( self: Pin<&mut &Async<T>>, cx: &mut Context<'_>, bufs: &mut [IoSliceMut<'_>] ) -> Poll<Result<usize, Error>>

§

impl<T> AsyncRead for &Mutex<T>
where T: AsyncRead + Unpin,

§

fn poll_read( self: Pin<&mut &Mutex<T>>, cx: &mut Context<'_>, buf: &mut [u8] ) -> Poll<Result<usize, Error>>

§

fn poll_read_vectored( self: Pin<&mut &Mutex<T>>, cx: &mut Context<'_>, bufs: &mut [IoSliceMut<'_>] ) -> Poll<Result<usize, Error>>

§

impl<T> AsyncRead for &mut T
where T: AsyncRead + Unpin + ?Sized,

§

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

§

fn poll_read_vectored( self: Pin<&mut &mut T>, cx: &mut Context<'_>, bufs: &mut [IoSliceMut<'_>] ) -> Poll<Result<usize, Error>>

§

impl<T> AsyncRead for Box<T>
where T: AsyncRead + Unpin + ?Sized,

§

fn poll_read( self: Pin<&mut Box<T>>, cx: &mut Context<'_>, buf: &mut [u8] ) -> Poll<Result<usize, Error>>

§

fn poll_read_vectored( self: Pin<&mut Box<T>>, cx: &mut Context<'_>, bufs: &mut [IoSliceMut<'_>] ) -> Poll<Result<usize, Error>>

§

impl<T> AsyncRead for Arc<T>
where &'a T: for<'a> AsyncRead,

§

fn poll_read( self: Pin<&mut Arc<T>>, cx: &mut Context<'_>, buf: &mut [u8] ) -> Poll<Result<usize, Error>>

§

fn poll_read_vectored( self: Pin<&mut Arc<T>>, cx: &mut Context<'_>, bufs: &mut [IoSliceMut<'_>] ) -> Poll<Result<usize, Error>>

§

impl<T> AsyncRead for AssertAsync<T>
where T: Read,

§

fn poll_read( self: Pin<&mut AssertAsync<T>>, _: &mut Context<'_>, buf: &mut [u8] ) -> Poll<Result<usize, Error>>

§

fn poll_read_vectored( self: Pin<&mut AssertAsync<T>>, _: &mut Context<'_>, bufs: &mut [IoSliceMut<'_>] ) -> Poll<Result<usize, Error>>

§

impl<T> AsyncRead for AssertAsync<T>
where T: Read,

§

fn poll_read( self: Pin<&mut AssertAsync<T>>, _: &mut Context<'_>, buf: &mut [u8] ) -> Poll<Result<usize, Error>>

§

fn poll_read_vectored( self: Pin<&mut AssertAsync<T>>, _: &mut Context<'_>, bufs: &mut [IoSliceMut<'_>] ) -> Poll<Result<usize, Error>>

§

impl<T> AsyncRead for Async<T>
where T: Read,

§

fn poll_read( self: Pin<&mut Async<T>>, cx: &mut Context<'_>, buf: &mut [u8] ) -> Poll<Result<usize, Error>>

§

fn poll_read_vectored( self: Pin<&mut Async<T>>, cx: &mut Context<'_>, bufs: &mut [IoSliceMut<'_>] ) -> Poll<Result<usize, Error>>

§

impl<T> AsyncRead for Async<T>
where T: IoSafe + Read,

§

fn poll_read( self: Pin<&mut Async<T>>, cx: &mut Context<'_>, buf: &mut [u8] ) -> Poll<Result<usize, Error>>

§

fn poll_read_vectored( self: Pin<&mut Async<T>>, cx: &mut Context<'_>, bufs: &mut [IoSliceMut<'_>] ) -> Poll<Result<usize, Error>>

§

impl<T> AsyncRead for Cursor<T>
where T: AsRef<[u8]> + Unpin,

§

fn poll_read( self: Pin<&mut Cursor<T>>, _cx: &mut Context<'_>, buf: &mut [u8] ) -> Poll<Result<usize, Error>>

§

fn poll_read_vectored( self: Pin<&mut Cursor<T>>, _: &mut Context<'_>, bufs: &mut [IoSliceMut<'_>] ) -> Poll<Result<usize, Error>>

§

impl<T> AsyncRead for Cursor<T>
where T: AsRef<[u8]> + Unpin,

§

fn poll_read( self: Pin<&mut Cursor<T>>, _cx: &mut Context<'_>, buf: &mut [u8] ) -> Poll<Result<usize, Error>>

§

fn poll_read_vectored( self: Pin<&mut Cursor<T>>, _: &mut Context<'_>, bufs: &mut [IoSliceMut<'_>] ) -> Poll<Result<usize, Error>>

§

impl<T> AsyncRead for Mutex<T>
where T: AsyncRead + Unpin,

§

fn poll_read( self: Pin<&mut Mutex<T>>, cx: &mut Context<'_>, buf: &mut [u8] ) -> Poll<Result<usize, Error>>

§

fn poll_read_vectored( self: Pin<&mut Mutex<T>>, cx: &mut Context<'_>, bufs: &mut [IoSliceMut<'_>] ) -> Poll<Result<usize, Error>>

§

impl<T> AsyncRead for ReadHalf<T>
where T: AsyncRead + Unpin,

§

fn poll_read( self: Pin<&mut ReadHalf<T>>, cx: &mut Context<'_>, buf: &mut [u8] ) -> Poll<Result<usize, Error>>

§

fn poll_read_vectored( self: Pin<&mut ReadHalf<T>>, cx: &mut Context<'_>, bufs: &mut [IoSliceMut<'_>] ) -> Poll<Result<usize, Error>>

§

impl<T> AsyncRead for ReadHalf<T>
where T: AsyncRead + Unpin,

§

fn poll_read( self: Pin<&mut ReadHalf<T>>, cx: &mut Context<'_>, buf: &mut [u8] ) -> Poll<Result<usize, Error>>

§

fn poll_read_vectored( self: Pin<&mut ReadHalf<T>>, cx: &mut Context<'_>, bufs: &mut [IoSliceMut<'_>] ) -> Poll<Result<usize, Error>>

§

impl<T> AsyncRead for SmolTransport<T>
where T: AsyncRead + Unpin, SmolTransport<T>: Unpin,

§

fn poll_read( self: Pin<&mut SmolTransport<T>>, cx: &mut Context<'_>, buf: &mut [u8] ) -> Poll<Result<usize, Error>>

§

fn poll_read_vectored( self: Pin<&mut SmolTransport<T>>, cx: &mut Context<'_>, bufs: &mut [IoSliceMut<'_>] ) -> Poll<Result<usize, Error>>

§

impl<T> AsyncRead for Unblock<T>
where T: Read + Send + 'static,

§

fn poll_read( self: Pin<&mut Unblock<T>>, cx: &mut Context<'_>, buf: &mut [u8] ) -> Poll<Result<usize, Error>>

§

impl<T, U> AsyncRead for Binding<T, U>
where T: AsyncRead + Unpin, U: AsyncRead + Unpin,

§

fn poll_read( self: Pin<&mut Binding<T, U>>, cx: &mut Context<'_>, buf: &mut [u8] ) -> Poll<Result<usize, Error>>

§

impl<Transport> AsyncRead for Upgrade<Transport>
where Transport: AsyncRead + Unpin,

§

fn poll_read( self: Pin<&mut Upgrade<Transport>>, cx: &mut Context<'_>, buf: &mut [u8] ) -> Poll<Result<usize, Error>>

Implementors§