Trait futures::io::AsyncRead [−][src]
pub trait AsyncRead {
pub fn poll_read(
self: Pin<&mut Self>,
cx: &mut Context<'_>,
buf: &mut [u8]
) -> Poll<Result<usize, Error>>;
pub fn poll_read_vectored(
self: Pin<&mut Self>,
cx: &mut Context<'_>,
bufs: &mut [IoSliceMut<'_>]
) -> Poll<Result<usize, Error>> { ... }
}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
pub fn poll_read(
self: Pin<&mut Self>,
cx: &mut Context<'_>,
buf: &mut [u8]
) -> Poll<Result<usize, Error>>[src]
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
pub fn poll_read_vectored(
self: Pin<&mut Self>,
cx: &mut Context<'_>,
bufs: &mut [IoSliceMut<'_>]
) -> Poll<Result<usize, Error>>[src]
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][src]
pub fn poll_read(
self: Pin<&mut &'_ [u8]>,
&mut Context<'_>,
buf: &mut [u8]
) -> Poll<Result<usize, Error>>[src]
self: Pin<&mut &'_ [u8]>,
&mut Context<'_>,
buf: &mut [u8]
) -> Poll<Result<usize, Error>>
pub fn poll_read_vectored(
self: Pin<&mut &'_ [u8]>,
&mut Context<'_>,
bufs: &mut [IoSliceMut<'_>]
) -> Poll<Result<usize, Error>>[src]
self: Pin<&mut &'_ [u8]>,
&mut Context<'_>,
bufs: &mut [IoSliceMut<'_>]
) -> Poll<Result<usize, Error>>
impl<T> AsyncRead for Box<T, Global> where
T: AsyncRead + Unpin + ?Sized, [src]
T: AsyncRead + Unpin + ?Sized,
pub fn poll_read(
self: Pin<&mut Box<T, Global>>,
cx: &mut Context<'_>,
buf: &mut [u8]
) -> Poll<Result<usize, Error>>[src]
self: Pin<&mut Box<T, Global>>,
cx: &mut Context<'_>,
buf: &mut [u8]
) -> Poll<Result<usize, Error>>
pub fn poll_read_vectored(
self: Pin<&mut Box<T, Global>>,
cx: &mut Context<'_>,
bufs: &mut [IoSliceMut<'_>]
) -> Poll<Result<usize, Error>>[src]
self: Pin<&mut Box<T, Global>>,
cx: &mut Context<'_>,
bufs: &mut [IoSliceMut<'_>]
) -> Poll<Result<usize, Error>>
impl<P> AsyncRead for Pin<P> where
P: DerefMut + Unpin,
<P as Deref>::Target: AsyncRead, [src]
P: DerefMut + Unpin,
<P as Deref>::Target: AsyncRead,
pub fn poll_read(
self: Pin<&mut Pin<P>>,
cx: &mut Context<'_>,
buf: &mut [u8]
) -> Poll<Result<usize, Error>>[src]
self: Pin<&mut Pin<P>>,
cx: &mut Context<'_>,
buf: &mut [u8]
) -> Poll<Result<usize, Error>>
pub fn poll_read_vectored(
self: Pin<&mut Pin<P>>,
cx: &mut Context<'_>,
bufs: &mut [IoSliceMut<'_>]
) -> Poll<Result<usize, Error>>[src]
self: Pin<&mut Pin<P>>,
cx: &mut Context<'_>,
bufs: &mut [IoSliceMut<'_>]
) -> Poll<Result<usize, Error>>
impl<'_, T> AsyncRead for &'_ mut T where
T: AsyncRead + Unpin + ?Sized, [src]
T: AsyncRead + Unpin + ?Sized,
pub fn poll_read(
self: Pin<&mut &'_ mut T>,
cx: &mut Context<'_>,
buf: &mut [u8]
) -> Poll<Result<usize, Error>>[src]
self: Pin<&mut &'_ mut T>,
cx: &mut Context<'_>,
buf: &mut [u8]
) -> Poll<Result<usize, Error>>
pub fn poll_read_vectored(
self: Pin<&mut &'_ mut T>,
cx: &mut Context<'_>,
bufs: &mut [IoSliceMut<'_>]
) -> Poll<Result<usize, Error>>[src]
self: Pin<&mut &'_ mut T>,
cx: &mut Context<'_>,
bufs: &mut [IoSliceMut<'_>]
) -> Poll<Result<usize, Error>>
Implementors
impl AsyncRead for Empty[src]
pub fn poll_read(
self: Pin<&mut Empty>,
&mut Context<'_>,
&mut [u8]
) -> Poll<Result<usize, Error>>[src]
self: Pin<&mut Empty>,
&mut Context<'_>,
&mut [u8]
) -> Poll<Result<usize, Error>>
impl AsyncRead for Repeat[src]
pub fn poll_read(
self: Pin<&mut Repeat>,
&mut Context<'_>,
buf: &mut [u8]
) -> Poll<Result<usize, Error>>[src]
self: Pin<&mut Repeat>,
&mut Context<'_>,
buf: &mut [u8]
) -> Poll<Result<usize, Error>>
pub fn poll_read_vectored(
self: Pin<&mut Repeat>,
cx: &mut Context<'_>,
bufs: &mut [IoSliceMut<'_>]
) -> Poll<Result<usize, Error>>[src]
self: Pin<&mut Repeat>,
cx: &mut Context<'_>,
bufs: &mut [IoSliceMut<'_>]
) -> Poll<Result<usize, Error>>
impl<A, B> AsyncRead for Either<A, B> where
B: AsyncRead,
A: AsyncRead, [src]
B: AsyncRead,
A: AsyncRead,
pub fn poll_read(
self: Pin<&mut Either<A, B>>,
cx: &mut Context<'_>,
buf: &mut [u8]
) -> Poll<Result<usize, Error>>[src]
self: Pin<&mut Either<A, B>>,
cx: &mut Context<'_>,
buf: &mut [u8]
) -> Poll<Result<usize, Error>>
pub fn poll_read_vectored(
self: Pin<&mut Either<A, B>>,
cx: &mut Context<'_>,
bufs: &mut [IoSliceMut<'_>]
) -> Poll<Result<usize, Error>>[src]
self: Pin<&mut Either<A, B>>,
cx: &mut Context<'_>,
bufs: &mut [IoSliceMut<'_>]
) -> Poll<Result<usize, Error>>
impl<R> AsyncRead for BufReader<R> where
R: AsyncRead, [src]
R: AsyncRead,
pub fn poll_read(
self: Pin<&mut BufReader<R>>,
cx: &mut Context<'_>,
buf: &mut [u8]
) -> Poll<Result<usize, Error>>[src]
self: Pin<&mut BufReader<R>>,
cx: &mut Context<'_>,
buf: &mut [u8]
) -> Poll<Result<usize, Error>>
pub fn poll_read_vectored(
self: Pin<&mut BufReader<R>>,
cx: &mut Context<'_>,
bufs: &mut [IoSliceMut<'_>]
) -> Poll<Result<usize, Error>>[src]
self: Pin<&mut BufReader<R>>,
cx: &mut Context<'_>,
bufs: &mut [IoSliceMut<'_>]
) -> Poll<Result<usize, Error>>
impl<R> AsyncRead for ReadHalf<R> where
R: AsyncRead, [src]
R: AsyncRead,
pub fn poll_read(
self: Pin<&mut ReadHalf<R>>,
cx: &mut Context<'_>,
buf: &mut [u8]
) -> Poll<Result<usize, Error>>[src]
self: Pin<&mut ReadHalf<R>>,
cx: &mut Context<'_>,
buf: &mut [u8]
) -> Poll<Result<usize, Error>>
pub fn poll_read_vectored(
self: Pin<&mut ReadHalf<R>>,
cx: &mut Context<'_>,
bufs: &mut [IoSliceMut<'_>]
) -> Poll<Result<usize, Error>>[src]
self: Pin<&mut ReadHalf<R>>,
cx: &mut Context<'_>,
bufs: &mut [IoSliceMut<'_>]
) -> Poll<Result<usize, Error>>
impl<R> AsyncRead for Take<R> where
R: AsyncRead, [src]
R: AsyncRead,
pub fn poll_read(
self: Pin<&mut Take<R>>,
cx: &mut Context<'_>,
buf: &mut [u8]
) -> Poll<Result<usize, Error>>[src]
self: Pin<&mut Take<R>>,
cx: &mut Context<'_>,
buf: &mut [u8]
) -> Poll<Result<usize, Error>>
impl<St> AsyncRead for IntoAsyncRead<St> where
St: TryStream<Error = Error> + Unpin,
<St as TryStream>::Ok: AsRef<[u8]>, [src]
St: TryStream<Error = Error> + Unpin,
<St as TryStream>::Ok: AsRef<[u8]>,
pub fn poll_read(
self: Pin<&mut IntoAsyncRead<St>>,
cx: &mut Context<'_>,
buf: &mut [u8]
) -> Poll<Result<usize, Error>>[src]
self: Pin<&mut IntoAsyncRead<St>>,
cx: &mut Context<'_>,
buf: &mut [u8]
) -> Poll<Result<usize, Error>>
impl<T> AsyncRead for AllowStdIo<T> where
T: Read, [src]
T: Read,
pub fn poll_read(
self: Pin<&mut AllowStdIo<T>>,
&mut Context<'_>,
buf: &mut [u8]
) -> Poll<Result<usize, Error>>[src]
self: Pin<&mut AllowStdIo<T>>,
&mut Context<'_>,
buf: &mut [u8]
) -> Poll<Result<usize, Error>>
pub fn poll_read_vectored(
self: Pin<&mut AllowStdIo<T>>,
&mut Context<'_>,
bufs: &mut [IoSliceMut<'_>]
) -> Poll<Result<usize, Error>>[src]
self: Pin<&mut AllowStdIo<T>>,
&mut Context<'_>,
bufs: &mut [IoSliceMut<'_>]
) -> Poll<Result<usize, Error>>
impl<T> AsyncRead for Cursor<T> where
T: AsRef<[u8]> + Unpin, [src]
T: AsRef<[u8]> + Unpin,
pub fn poll_read(
self: Pin<&mut Cursor<T>>,
_cx: &mut Context<'_>,
buf: &mut [u8]
) -> Poll<Result<usize, Error>>[src]
self: Pin<&mut Cursor<T>>,
_cx: &mut Context<'_>,
buf: &mut [u8]
) -> Poll<Result<usize, Error>>
pub fn poll_read_vectored(
self: Pin<&mut Cursor<T>>,
&mut Context<'_>,
bufs: &mut [IoSliceMut<'_>]
) -> Poll<Result<usize, Error>>[src]
self: Pin<&mut Cursor<T>>,
&mut Context<'_>,
bufs: &mut [IoSliceMut<'_>]
) -> Poll<Result<usize, Error>>
impl<T, U> AsyncRead for Chain<T, U> where
T: AsyncRead,
U: AsyncRead, [src]
T: AsyncRead,
U: AsyncRead,
pub fn poll_read(
self: Pin<&mut Chain<T, U>>,
cx: &mut Context<'_>,
buf: &mut [u8]
) -> Poll<Result<usize, Error>>[src]
self: Pin<&mut Chain<T, U>>,
cx: &mut Context<'_>,
buf: &mut [u8]
) -> Poll<Result<usize, Error>>
pub fn poll_read_vectored(
self: Pin<&mut Chain<T, U>>,
cx: &mut Context<'_>,
bufs: &mut [IoSliceMut<'_>]
) -> Poll<Result<usize, Error>>[src]
self: Pin<&mut Chain<T, U>>,
cx: &mut Context<'_>,
bufs: &mut [IoSliceMut<'_>]
) -> Poll<Result<usize, Error>>
impl<W> AsyncRead for BufWriter<W> where
W: AsyncRead, [src]
W: AsyncRead,