Trait Read
pub trait Read
Reads bytes from a source.
This trait is similar to std::io::Read, but supports asynchronous reads.
Implementing Read
Implementations should read data into the provided ReadBufCursor and
advance the cursor to indicate how many bytes were written. The simplest
and safest approach is to use [ReadBufCursor::put_slice]:
use ;
use Pin;
use ;
use io;
For more advanced use cases where you need direct access to the buffer
(e.g., when interfacing with APIs that write directly to a pointer),
you can use the unsafe ReadBufCursor::as_mut and ReadBufCursor::advance
methods. See their documentation for safety requirements.
Required Methods
fn poll_read(self: Pin<&mut Self>, cx: &mut Context<'_>, buf: ReadBufCursor<'_>) -> Poll<Result<(), Error>>Attempts to read bytes into the
buf.On success, returns
Poll::Ready(Ok(()))and places data in the unfilled portion ofbuf. If no data was read (buf.remaining()is unchanged), it implies that EOF has been reached.If no data is available for reading, the method returns
Poll::Pendingand arranges for the current task (viacx.waker()) to receive a notification when the object becomes readable or is closed.