embedded_io/impls/
boxx.rs

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