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§

source

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§

source

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§

source§

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

source§

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

source§

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

source§

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

source§

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

source§

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

source§

impl AsyncRead for &[u8]

source§

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

source§

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

source§

impl AsyncRead for SubstreamBox

source§

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

source§

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

source§

impl AsyncRead for DummyStream

source§

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

source§

impl<S> AsyncRead for RwStreamSink<S>where S: TryStream<Error = Error>, <S as TryStream>::Ok: AsRef<[u8]>,

source§

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

source§

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

source§

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

source§

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

source§

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

source§

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

source§

impl AsyncRead for TcpStream

source§

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

source§

impl AsyncRead for Connection

source§

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

source§

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

source§

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

source§

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

source§

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

source§

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

source§

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

source§

impl AsyncRead for Stream

source§

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

source§

impl<T> AsyncRead for Compat<T>where T: AsyncRead,

source§

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

Implementors§

source§

impl AsyncRead for Empty

source§

impl AsyncRead for Repeat

source§

impl<A, B> AsyncRead for Either<A, B>where A: AsyncRead, B: AsyncRead,

source§

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

source§

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

source§

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

source§

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

source§

impl<St> AsyncRead for IntoAsyncRead<St>where St: TryStream<Error = Error>, <St as TryStream>::Ok: AsRef<[u8]>,

source§

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

source§

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

source§

impl<T, U> AsyncRead for Chain<T, U>where T: AsyncRead, U: AsyncRead,

source§

impl<W> AsyncRead for BufWriter<W>where W: AsyncRead,