embedded_io_async/impls/
boxx.rs

1use crate::{BufRead, Read, Seek, SeekFrom, Write};
2use alloc::boxed::Box;
3
4#[cfg_attr(docsrs, doc(cfg(any(feature = "std", feature = "alloc"))))]
5impl<T: ?Sized + Read> Read for Box<T> {
6    #[inline]
7    async fn read(&mut self, buf: &mut [u8]) -> Result<usize, Self::Error> {
8        T::read(self, buf).await
9    }
10
11    #[inline]
12    async fn read_exact(
13        &mut self,
14        buf: &mut [u8],
15    ) -> Result<(), crate::ReadExactError<Self::Error>> {
16        T::read_exact(self, buf).await
17    }
18}
19
20#[cfg_attr(docsrs, doc(cfg(any(feature = "std", feature = "alloc"))))]
21impl<T: ?Sized + BufRead> BufRead for Box<T> {
22    #[inline]
23    async fn fill_buf(&mut self) -> Result<&[u8], Self::Error> {
24        T::fill_buf(self).await
25    }
26
27    #[inline]
28    fn consume(&mut self, amt: usize) {
29        T::consume(self, amt);
30    }
31}
32
33#[cfg_attr(docsrs, doc(cfg(any(feature = "std", feature = "alloc"))))]
34impl<T: ?Sized + Write> Write for Box<T> {
35    #[inline]
36    async fn write(&mut self, buf: &[u8]) -> Result<usize, Self::Error> {
37        T::write(self, buf).await
38    }
39
40    #[inline]
41    async fn write_all(&mut self, buf: &[u8]) -> Result<(), Self::Error> {
42        T::write_all(self, buf).await
43    }
44
45    #[inline]
46    async fn flush(&mut self) -> Result<(), Self::Error> {
47        T::flush(self).await
48    }
49}
50
51#[cfg_attr(docsrs, doc(cfg(any(feature = "std", feature = "alloc"))))]
52impl<T: ?Sized + Seek> Seek for Box<T> {
53    #[inline]
54    async fn seek(&mut self, pos: SeekFrom) -> Result<u64, Self::Error> {
55        T::seek(self, pos).await
56    }
57
58    #[inline]
59    async fn rewind(&mut self) -> Result<(), Self::Error> {
60        T::rewind(self).await
61    }
62
63    #[inline]
64    async fn stream_position(&mut self) -> Result<u64, Self::Error> {
65        T::stream_position(self).await
66    }
67}