Skip to main content

externally_driven_async_rt/io/
async_write.rs

1use core::future::Future;
2
3use crate::Context;
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        E: 'static,
22        const EVENTS: usize,
23        const TASKS: usize,
24        const TASK_SIZE: usize,
25        const ROOT_TASK_SIZE: usize,
26        const TIMERS: usize,
27        const FDS: usize,
28    >(
29        &'a mut self,
30        ctx: &'a Context<'_, E, EVENTS, TASKS, TASK_SIZE, ROOT_TASK_SIZE, TIMERS, FDS>,
31        buf: &'a [u8],
32    ) -> impl Future<Output = Result<usize, Self::Error>>;
33
34    /// Makes sure that everything accepted by [`write`](Self::write) is sent.
35    ///
36    /// # Errors
37    ///
38    /// Returns an error if writing fails.
39    ///
40    /// # Cancel safety
41    ///
42    /// Implementations in this crate are cancel safe.
43    fn flush<
44        'a,
45        E: 'static,
46        const EVENTS: usize,
47        const TASKS: usize,
48        const TASK_SIZE: usize,
49        const ROOT_TASK_SIZE: usize,
50        const TIMERS: usize,
51        const FDS: usize,
52    >(
53        &'a mut self,
54        ctx: &'a Context<'_, E, EVENTS, TASKS, TASK_SIZE, ROOT_TASK_SIZE, TIMERS, FDS>,
55    ) -> impl Future<Output = Result<(), Self::Error>>;
56}