Trait async_hal::io::AsyncRead

source ·
pub trait AsyncRead {
    type Error;

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

    // Provided method
    fn read<'a>(&'a mut self, buf: &'a mut [u8]) -> Read<'a, Self> 
       where Self: Unpin { ... }
}
Expand description

Read bytes asynchronously.

Required Associated Types§

Required Methods§

source

fn poll_read( self: Pin<&mut Self>, cx: &mut Context<'_>, buf: &mut [u8] ) -> Poll<Result<usize, Self::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, this method returns Poll::Pending and arranges for the current task to be woken.

Provided Methods§

source

fn read<'a>(&'a mut self, buf: &'a mut [u8]) -> Read<'a, Self> where Self: Unpin,

Tries to read some bytes directly into the given buf in asynchronous manner, returning a future type.

The returned future will resolve to both the I/O stream and the buffer as well as the number of bytes read once the read operation is completed.

use async_hal::io::AsyncRead;

let mut bytes = [1, 2, 3].as_ref();
let mut buf = [0; 3];

bytes.read(&mut buf).await?;   

assert_eq!([1, 2, 3], buf);

Implementations on Foreign Types§

source§

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

§

type Error = <T as AsyncRead>::Error

source§

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

source§

impl AsyncRead for &[u8]

§

type Error = Void

source§

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

Implementors§

source§

impl<R: AsyncRead> AsyncRead for BufReader<'_, R>

§

type Error = <R as AsyncRead>::Error

source§

impl<T, E> AsyncRead for Reader<T>where T: Stream<Item = Result<u8, E>> + Unpin,

§

type Error = E