Write bytes to a sink.
| 2 | |
| 3 | /// Write bytes to a sink. |
| 4 | pub trait AsyncWrite { |
| 5 | // Required methods |
| 6 | async fn write(&mut self, buf: &[u8]) -> io::Result<usize>; |
| 7 | async fn flush(&mut self) -> io::Result<()>; |
| 8 | |
| 9 | async fn write_all(&mut self, buf: &[u8]) -> io::Result<()> { |
| 10 | let mut to_write = &buf[0..]; |
| 11 | loop { |
| 12 | let bytes_written = self.write(to_write).await?; |
| 13 | to_write = &to_write[bytes_written..]; |
| 14 | if to_write.is_empty() { |
| 15 | return Ok(()); |
| 16 | } |
| 17 | } |
| 18 | } |
| 19 | |
| 20 | // If the `AsyncWrite` implementation is an unbuffered wrapper around an |
| 21 | // `AsyncOutputStream`, some I/O operations can be more efficient. |
| 22 | #[inline] |
| 23 | fn as_async_output_stream(&self) -> Option<&io::AsyncOutputStream> { |
| 24 | None |
| 25 | } |
| 26 | } |
| 27 | |
| 28 | impl<W: AsyncWrite + ?Sized> AsyncWrite for &mut W { |
| 29 | #[inline] |
nothing calls this directly
no outgoing calls
no test coverage detected