embedded_io/impls/
boxx.rs1use 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 #[inline]
17 fn read_exact(&mut self, buf: &mut [u8]) -> Result<(), crate::ReadExactError<Self::Error>> {
18 T::read_exact(self, buf)
19 }
20}
21
22#[cfg_attr(docsrs, doc(cfg(any(feature = "std", feature = "alloc"))))]
23impl<T: ?Sized + BufRead> BufRead for Box<T> {
24 fn fill_buf(&mut self) -> Result<&[u8], Self::Error> {
25 T::fill_buf(self)
26 }
27
28 #[inline]
29 fn consume(&mut self, amt: usize) {
30 T::consume(self, amt);
31 }
32}
33
34#[cfg_attr(docsrs, doc(cfg(any(feature = "std", feature = "alloc"))))]
35impl<T: ?Sized + Write> Write for Box<T> {
36 #[inline]
37 fn write(&mut self, buf: &[u8]) -> Result<usize, Self::Error> {
38 T::write(self, buf)
39 }
40
41 #[inline]
42 fn write_all(&mut self, buf: &[u8]) -> Result<(), Self::Error> {
43 T::write_all(self, buf)
44 }
45
46 #[inline]
47 fn write_fmt(
48 &mut self,
49 fmt: core::fmt::Arguments<'_>,
50 ) -> Result<(), crate::WriteFmtError<Self::Error>> {
51 T::write_fmt(self, fmt)
52 }
53
54 #[inline]
55 fn flush(&mut self) -> Result<(), Self::Error> {
56 T::flush(self)
57 }
58}
59
60#[cfg_attr(docsrs, doc(cfg(any(feature = "std", feature = "alloc"))))]
61impl<T: ?Sized + Seek> Seek for Box<T> {
62 #[inline]
63 fn seek(&mut self, pos: crate::SeekFrom) -> Result<u64, Self::Error> {
64 T::seek(self, pos)
65 }
66
67 #[inline]
68 fn rewind(&mut self) -> Result<(), Self::Error> {
69 T::rewind(self)
70 }
71
72 #[inline]
73 fn stream_position(&mut self) -> Result<u64, Self::Error> {
74 T::stream_position(self)
75 }
76
77 #[inline]
78 fn seek_relative(&mut self, offset: i64) -> Result<(), Self::Error> {
79 T::seek_relative(self, offset)
80 }
81}
82
83#[cfg_attr(docsrs, doc(cfg(any(feature = "std", feature = "alloc"))))]
84impl<T: ?Sized + ReadReady> ReadReady for Box<T> {
85 #[inline]
86 fn read_ready(&mut self) -> Result<bool, Self::Error> {
87 T::read_ready(self)
88 }
89}
90
91#[cfg_attr(docsrs, doc(cfg(any(feature = "std", feature = "alloc"))))]
92impl<T: ?Sized + WriteReady> WriteReady for Box<T> {
93 #[inline]
94 fn write_ready(&mut self) -> Result<bool, Self::Error> {
95 T::write_ready(self)
96 }
97}