Trait futures_util::io::AsyncRead[][src]

pub trait AsyncRead {
    fn poll_read(
        self: Pin<&mut Self>,
        cx: &mut Context<'_>,
        buf: &mut [u8]
    ) -> Poll<Result<usize, Error>>; unsafe fn initializer(&self) -> Initializer { ... }
fn poll_read_vectored(
        self: Pin<&mut Self>,
        cx: &mut Context<'_>,
        bufs: &mut [IoSliceMut<'_>]
    ) -> Poll<Result<usize, Error>> { ... } }
This is supported on crate feature io only.
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>>
[src]

Expand description

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.

Loading content...

Provided methods

unsafe fn initializer(&self) -> Initializer[src]

Expand description

Determines if this AsyncReader can work with buffers of uninitialized memory.

The default implementation returns an initializer which will zero buffers.

This method is only available when the read-initializer feature of this library is activated.

Safety

This method is unsafe because an AsyncReader could otherwise return a non-zeroing Initializer from another AsyncRead type without an unsafe block.

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

Expand description

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.

Loading content...

Implementations on Foreign Types

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

pub unsafe fn initializer(&self) -> Initializer[src]

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

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

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

pub unsafe fn initializer(&self) -> Initializer[src]

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

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

impl<'_> AsyncRead for &'_ [u8][src]

pub unsafe fn initializer(&self) -> Initializer[src]

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

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

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

pub unsafe fn initializer(&self) -> Initializer[src]

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

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

Loading content...

Implementors

impl AsyncRead for Empty[src]

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

unsafe fn initializer(&self) -> Initializer[src]

impl AsyncRead for Repeat[src]

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

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

unsafe fn initializer(&self) -> Initializer[src]

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

unsafe fn initializer(&self) -> Initializer[src]

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

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

impl<R: AsyncRead01> AsyncRead for Compat01As03<R>[src]

This is supported on crate features io-compat and compat only.

unsafe fn initializer(&self) -> Initializer[src]

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

impl<R: AsyncRead> AsyncRead for BufReader<R>[src]

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

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

unsafe fn initializer(&self) -> Initializer[src]

impl<R: AsyncRead> AsyncRead for ReadHalf<R>[src]

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

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

impl<R: AsyncRead> AsyncRead for Take<R>[src]

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

unsafe fn initializer(&self) -> Initializer[src]

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

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

impl<T> AsyncRead for AllowStdIo<T> where
    T: Read
[src]

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

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

unsafe fn initializer(&self) -> Initializer[src]

impl<T, U> AsyncRead for Chain<T, U> where
    T: AsyncRead,
    U: AsyncRead
[src]

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

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

unsafe fn initializer(&self) -> Initializer[src]

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

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

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

impl<W: AsyncRead> AsyncRead for BufWriter<W>[src]

unsafe fn initializer(&self) -> Initializer[src]

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

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

Loading content...