Skip to content

Commit 87dcbf7

Browse files
committed
io: Fix FromStd::read_exact by mapping std::io::ErrorKind::UnexpectedEof to ReadExactError::UnexpectedEof
1 parent 1ffedc7 commit 87dcbf7

File tree

1 file changed

+11
-1
lines changed
  • embedded-io-adapters/src

1 file changed

+11
-1
lines changed

embedded-io-adapters/src/std.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//! Adapters to/from `std::io` traits.
22
3-
use embedded_io::Error as _;
3+
use embedded_io::{Error as _, ReadExactError};
44

55
/// Adapter from `std::io` traits.
66
#[derive(Clone)]
@@ -40,6 +40,16 @@ impl<T: std::io::Read + ?Sized> embedded_io::Read for FromStd<T> {
4040
fn read(&mut self, buf: &mut [u8]) -> Result<usize, Self::Error> {
4141
self.inner.read(buf)
4242
}
43+
44+
fn read_exact(&mut self, buf: &mut [u8]) -> Result<(), ReadExactError<Self::Error>> {
45+
match self.inner.read_exact(buf) {
46+
Ok(()) => Ok(()),
47+
Err(error) if error.kind() == std::io::ErrorKind::UnexpectedEof => {
48+
Err(embedded_io::ReadExactError::UnexpectedEof)
49+
}
50+
Err(error) => Err(error.into()),
51+
}
52+
}
4353
}
4454

4555
impl<T: std::io::BufRead + ?Sized> embedded_io::BufRead for FromStd<T> {

0 commit comments

Comments
 (0)