externally_driven_async_rt/io/async_write.rs
1use core::future::Future;
2
3use crate::{Context, State};
4
5/// A stream that can be written to asynchronously.
6pub trait AsyncWrite {
7 /// The error returned by [`write`](Self::write) and [`flush`](Self::flush).
8 type Error;
9
10 /// Writes from a given buffer, returns the number of written bytes.
11 ///
12 /// # Errors
13 ///
14 /// Returns an error if writing fails.
15 ///
16 /// # Cancel safety
17 ///
18 /// Implementations in this crate are cancel safe.
19 fn write<
20 'a,
21 S: State,
22 const TASKS: usize,
23 const TASK_SIZE: usize,
24 const ROOT_TASK_SIZE: usize,
25 const TIMERS: usize,
26 const FDS: usize,
27 >(
28 &'a mut self,
29 ctx: &'a Context<'_, S, TASKS, TASK_SIZE, ROOT_TASK_SIZE, TIMERS, FDS>,
30 buf: &'a [u8],
31 ) -> impl Future<Output = Result<usize, Self::Error>>;
32
33 /// Makes sure that everything accepted by [`write`](Self::write) is sent.
34 ///
35 /// # Errors
36 ///
37 /// Returns an error if writing fails.
38 ///
39 /// # Cancel safety
40 ///
41 /// Implementations in this crate are cancel safe.
42 fn flush<
43 'a,
44 S: State,
45 const TASKS: usize,
46 const TASK_SIZE: usize,
47 const ROOT_TASK_SIZE: usize,
48 const TIMERS: usize,
49 const FDS: usize,
50 >(
51 &'a mut self,
52 ctx: &'a Context<'_, S, TASKS, TASK_SIZE, ROOT_TASK_SIZE, TIMERS, FDS>,
53 ) -> impl Future<Output = Result<(), Self::Error>>;
54}