|
| 1 | +use crate::{BufRead, Read, Seek, SeekFrom, Write}; |
| 2 | +use alloc::boxed::Box; |
| 3 | + |
| 4 | +#[cfg_attr(docsrs, doc(cfg(any(feature = "std", feature = "alloc"))))] |
| 5 | +impl<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 | + |
| 12 | +#[cfg_attr(docsrs, doc(cfg(any(feature = "std", feature = "alloc"))))] |
| 13 | +impl<T: ?Sized + BufRead> BufRead for Box<T> { |
| 14 | + #[inline] |
| 15 | + async fn fill_buf(&mut self) -> Result<&[u8], Self::Error> { |
| 16 | + T::fill_buf(self).await |
| 17 | + } |
| 18 | + |
| 19 | + #[inline] |
| 20 | + fn consume(&mut self, amt: usize) { |
| 21 | + T::consume(self, amt) |
| 22 | + } |
| 23 | +} |
| 24 | + |
| 25 | +#[cfg_attr(docsrs, doc(cfg(any(feature = "std", feature = "alloc"))))] |
| 26 | +impl<T: ?Sized + Write> Write for Box<T> { |
| 27 | + #[inline] |
| 28 | + async fn write(&mut self, buf: &[u8]) -> Result<usize, Self::Error> { |
| 29 | + T::write(self, buf).await |
| 30 | + } |
| 31 | + |
| 32 | + #[inline] |
| 33 | + async fn flush(&mut self) -> Result<(), Self::Error> { |
| 34 | + T::flush(self).await |
| 35 | + } |
| 36 | +} |
| 37 | + |
| 38 | +#[cfg_attr(docsrs, doc(cfg(any(feature = "std", feature = "alloc"))))] |
| 39 | +impl<T: ?Sized + Seek> Seek for Box<T> { |
| 40 | + #[inline] |
| 41 | + async fn seek(&mut self, pos: SeekFrom) -> Result<u64, Self::Error> { |
| 42 | + T::seek(self, pos).await |
| 43 | + } |
| 44 | +} |
0 commit comments