Skip to content

Commit 74c8db4

Browse files
authored
Merge pull request #705 from Conaclos/box-forward-calls
[io] Forward calls in Box adapters
2 parents bc825d0 + 9bb5dea commit 74c8db4

File tree

2 files changed

+57
-0
lines changed

2 files changed

+57
-0
lines changed

embedded-io-async/src/impls/boxx.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,14 @@ impl<T: ?Sized + Read> Read for Box<T> {
77
async fn read(&mut self, buf: &mut [u8]) -> Result<usize, Self::Error> {
88
T::read(self, buf).await
99
}
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+
}
1018
}
1119

1220
#[cfg_attr(docsrs, doc(cfg(any(feature = "std", feature = "alloc"))))]
@@ -29,6 +37,11 @@ impl<T: ?Sized + Write> Write for Box<T> {
2937
T::write(self, buf).await
3038
}
3139

40+
#[inline]
41+
async fn write_all(&mut self, buf: &[u8]) -> Result<(), Self::Error> {
42+
T::write_all(self, buf).await
43+
}
44+
3245
#[inline]
3346
async fn flush(&mut self) -> Result<(), Self::Error> {
3447
T::flush(self).await
@@ -41,4 +54,14 @@ impl<T: ?Sized + Seek> Seek for Box<T> {
4154
async fn seek(&mut self, pos: SeekFrom) -> Result<u64, Self::Error> {
4255
T::seek(self, pos).await
4356
}
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+
}
4467
}

embedded-io/src/impls/boxx.rs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@ impl<T: ?Sized + Read> Read for Box<T> {
1212
fn read(&mut self, buf: &mut [u8]) -> Result<usize, Self::Error> {
1313
T::read(self, buf)
1414
}
15+
16+
#[inline]
17+
fn read_exact(&mut self, buf: &mut [u8]) -> Result<(), crate::ReadExactError<Self::Error>> {
18+
T::read_exact(self, buf)
19+
}
1520
}
1621

1722
#[cfg_attr(docsrs, doc(cfg(any(feature = "std", feature = "alloc"))))]
@@ -20,6 +25,7 @@ impl<T: ?Sized + BufRead> BufRead for Box<T> {
2025
T::fill_buf(self)
2126
}
2227

28+
#[inline]
2329
fn consume(&mut self, amt: usize) {
2430
T::consume(self, amt);
2531
}
@@ -32,6 +38,19 @@ impl<T: ?Sized + Write> Write for Box<T> {
3238
T::write(self, buf)
3339
}
3440

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+
3554
#[inline]
3655
fn flush(&mut self) -> Result<(), Self::Error> {
3756
T::flush(self)
@@ -44,6 +63,21 @@ impl<T: ?Sized + Seek> Seek for Box<T> {
4463
fn seek(&mut self, pos: crate::SeekFrom) -> Result<u64, Self::Error> {
4564
T::seek(self, pos)
4665
}
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+
}
4781
}
4882

4983
#[cfg_attr(docsrs, doc(cfg(any(feature = "std", feature = "alloc"))))]

0 commit comments

Comments
 (0)