Skip to main content

externally_driven_async_rt/io/
async_read.rs

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