[−][src]Trait futures_io::AsyncRead
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>>
self: Pin<&mut Self>,
cx: &mut Context,
buf: &mut [u8]
) -> Poll<Result<usize>>
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
unsafe fn initializer(&self) -> Initializer
Determines if this AsyncRead
er can work with buffers of
uninitialized memory.
The default implementation returns an initializer which will zero buffers.
Safety
This method is unsafe
because and AsyncRead
er 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>>
self: Pin<&mut Self>,
cx: &mut Context,
bufs: &mut [IoSliceMut]
) -> Poll<Result<usize>>
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
buffer in bufs
. 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<T: ?Sized + AsyncRead + Unpin> AsyncRead for Box<T>
[src]
unsafe fn initializer(&self) -> Initializer
[src]
fn poll_read(
self: Pin<&mut Self>,
cx: &mut Context,
buf: &mut [u8]
) -> Poll<Result<usize>>
[src]
self: Pin<&mut Self>,
cx: &mut Context,
buf: &mut [u8]
) -> Poll<Result<usize>>
fn poll_read_vectored(
self: Pin<&mut Self>,
cx: &mut Context,
bufs: &mut [IoSliceMut]
) -> Poll<Result<usize>>
[src]
self: Pin<&mut Self>,
cx: &mut Context,
bufs: &mut [IoSliceMut]
) -> Poll<Result<usize>>
impl<'_, T: ?Sized + AsyncRead + Unpin> AsyncRead for &'_ mut T
[src]
unsafe fn initializer(&self) -> Initializer
[src]
fn poll_read(
self: Pin<&mut Self>,
cx: &mut Context,
buf: &mut [u8]
) -> Poll<Result<usize>>
[src]
self: Pin<&mut Self>,
cx: &mut Context,
buf: &mut [u8]
) -> Poll<Result<usize>>
fn poll_read_vectored(
self: Pin<&mut Self>,
cx: &mut Context,
bufs: &mut [IoSliceMut]
) -> Poll<Result<usize>>
[src]
self: Pin<&mut Self>,
cx: &mut Context,
bufs: &mut [IoSliceMut]
) -> Poll<Result<usize>>
impl<P> AsyncRead for Pin<P> where
P: DerefMut + Unpin,
P::Target: AsyncRead,
[src]
P: DerefMut + Unpin,
P::Target: AsyncRead,
unsafe fn initializer(&self) -> Initializer
[src]
fn poll_read(
self: Pin<&mut Self>,
cx: &mut Context,
buf: &mut [u8]
) -> Poll<Result<usize>>
[src]
self: Pin<&mut Self>,
cx: &mut Context,
buf: &mut [u8]
) -> Poll<Result<usize>>
fn poll_read_vectored(
self: Pin<&mut Self>,
cx: &mut Context,
bufs: &mut [IoSliceMut]
) -> Poll<Result<usize>>
[src]
self: Pin<&mut Self>,
cx: &mut Context,
bufs: &mut [IoSliceMut]
) -> Poll<Result<usize>>
impl<'_> AsyncRead for &'_ [u8]
[src]
unsafe fn initializer(&self) -> Initializer
[src]
fn poll_read(
self: Pin<&mut Self>,
_: &mut Context,
buf: &mut [u8]
) -> Poll<Result<usize>>
[src]
self: Pin<&mut Self>,
_: &mut Context,
buf: &mut [u8]
) -> Poll<Result<usize>>
fn poll_read_vectored(
self: Pin<&mut Self>,
_: &mut Context,
bufs: &mut [IoSliceMut]
) -> Poll<Result<usize>>
[src]
self: Pin<&mut Self>,
_: &mut Context,
bufs: &mut [IoSliceMut]
) -> Poll<Result<usize>>
impl<T: AsRef<[u8]> + Unpin> AsyncRead for Cursor<T>
[src]
unsafe fn initializer(&self) -> Initializer
[src]
fn poll_read(
self: Pin<&mut Self>,
_: &mut Context,
buf: &mut [u8]
) -> Poll<Result<usize>>
[src]
self: Pin<&mut Self>,
_: &mut Context,
buf: &mut [u8]
) -> Poll<Result<usize>>
fn poll_read_vectored(
self: Pin<&mut Self>,
_: &mut Context,
bufs: &mut [IoSliceMut]
) -> Poll<Result<usize>>
[src]
self: Pin<&mut Self>,
_: &mut Context,
bufs: &mut [IoSliceMut]
) -> Poll<Result<usize>>