Skip to content

Commit ef9b7a7

Browse files
authored
Merge pull request #701 from Conaclos/std-io-adapter-forward-calls
io-adapter: forward calls to the std adapter
2 parents e12dbf6 + 4cfb197 commit ef9b7a7

File tree

1 file changed

+44
-0
lines changed
  • embedded-io-adapters/src

1 file changed

+44
-0
lines changed

embedded-io-adapters/src/std.rs

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,18 @@ impl<T: std::io::Write + ?Sized> embedded_io::Write for FromStd<T> {
6060
Err(e) => Err(e),
6161
}
6262
}
63+
64+
fn write_all(&mut self, buf: &[u8]) -> Result<(), Self::Error> {
65+
self.inner.write_all(buf)
66+
}
67+
68+
fn write_fmt(
69+
&mut self,
70+
fmt: core::fmt::Arguments<'_>,
71+
) -> Result<(), embedded_io::WriteFmtError<Self::Error>> {
72+
Ok(self.inner.write_fmt(fmt)?)
73+
}
74+
6375
fn flush(&mut self) -> Result<(), Self::Error> {
6476
self.inner.flush()
6577
}
@@ -69,6 +81,14 @@ impl<T: std::io::Seek + ?Sized> embedded_io::Seek for FromStd<T> {
6981
fn seek(&mut self, pos: embedded_io::SeekFrom) -> Result<u64, Self::Error> {
7082
self.inner.seek(pos.into())
7183
}
84+
85+
fn rewind(&mut self) -> Result<(), Self::Error> {
86+
self.inner.rewind()
87+
}
88+
89+
fn stream_position(&mut self) -> Result<u64, Self::Error> {
90+
self.inner.stream_position()
91+
}
7292
}
7393

7494
/// Adapter to `std::io` traits.
@@ -115,6 +135,22 @@ impl<T: embedded_io::Write + ?Sized> std::io::Write for ToStd<T> {
115135
Err(e) => Err(to_std_error(e)),
116136
}
117137
}
138+
139+
fn write_all(&mut self, buf: &[u8]) -> Result<(), std::io::Error> {
140+
self.inner.write_all(buf).map_err(to_std_error)
141+
}
142+
143+
fn write_fmt(&mut self, fmt: core::fmt::Arguments<'_>) -> Result<(), std::io::Error> {
144+
match self.inner.write_fmt(fmt) {
145+
Ok(()) => Ok(()),
146+
Err(e @ embedded_io::WriteFmtError::FmtError) => Err(std::io::Error::new(
147+
std::io::ErrorKind::Other,
148+
format!("{e:?}"),
149+
)),
150+
Err(embedded_io::WriteFmtError::Other(e)) => Err(to_std_error(e)),
151+
}
152+
}
153+
118154
fn flush(&mut self) -> Result<(), std::io::Error> {
119155
self.inner.flush().map_err(to_std_error)
120156
}
@@ -124,6 +160,14 @@ impl<T: embedded_io::Seek + ?Sized> std::io::Seek for ToStd<T> {
124160
fn seek(&mut self, pos: std::io::SeekFrom) -> Result<u64, std::io::Error> {
125161
self.inner.seek(pos.into()).map_err(to_std_error)
126162
}
163+
164+
fn rewind(&mut self) -> Result<(), std::io::Error> {
165+
self.inner.rewind().map_err(to_std_error)
166+
}
167+
168+
fn stream_position(&mut self) -> Result<u64, std::io::Error> {
169+
self.inner.stream_position().map_err(to_std_error)
170+
}
127171
}
128172

129173
/// Convert a embedded-io error to a [`std::io::Error`]

0 commit comments

Comments
 (0)