externally_driven_async_rt/io/async_read.rs
1use core::future::Future;
2
3use crate::Context;
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 E: 'static,
24 const EVENTS: usize,
25 const TASKS: usize,
26 const TASK_SIZE: usize,
27 const ROOT_TASK_SIZE: usize,
28 const TIMERS: usize,
29 const FDS: usize,
30 >(
31 &'a mut self,
32 ctx: &'a Context<'_, E, EVENTS, TASKS, TASK_SIZE, ROOT_TASK_SIZE, TIMERS, FDS>,
33 buf: &'a mut [u8],
34 ) -> impl Future<Output = Result<usize, Self::Error>>;
35}