externally_driven_async_rt/io/async_write.rs
1use core::future::Future;
2
3/// A stream that can be written to asynchronously.
4pub trait AsyncWrite {
5 /// The error returned by [`write`](Self::write) and [`flush`](Self::flush).
6 type Error;
7
8 /// Writes from a given buffer, returns the number of written bytes.
9 ///
10 /// # Errors
11 ///
12 /// Returns an error if writing fails.
13 ///
14 /// # Cancel safety
15 ///
16 /// Implementations in this crate are cancel safe.
17 fn write<'a>(&'a mut self, buf: &'a [u8]) -> impl Future<Output = Result<usize, Self::Error>>;
18
19 /// Makes sure that everything accepted by [`write`](Self::write) is sent.
20 ///
21 /// # Errors
22 ///
23 /// Returns an error if writing fails.
24 ///
25 /// # Cancel safety
26 ///
27 /// Implementations in this crate are cancel safe.
28 fn flush(&mut self) -> impl Future<Output = Result<(), Self::Error>>;
29}