Skip to main content

externally_driven_async_rt/io/
async_read.rs

1use core::future::Future;
2
3/// A stream that can be read from asynchronously.
4pub trait AsyncRead {
5    /// The error returned by [`read`](Self::read).
6    type Error;
7
8    /// Reads into a given buffer, returns the number of read bytes.
9    ///
10    /// Returns `0` if the stream is closed (or if the buffer is empty).
11    ///
12    /// # Errors
13    ///
14    /// Returns an error if reading fails.
15    ///
16    /// # Cancel safety
17    ///
18    /// Implementations in this crate are cancel safe.
19    fn read<'a>(
20        &'a mut self,
21        buf: &'a mut [u8],
22    ) -> impl Future<Output = Result<usize, Self::Error>>;
23}