Skip to content

Commit c08d859

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

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

embedded-io-adapters/Cargo.toml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,7 @@ description = "Adapters between the `embedded-io` traits and other I/O traits"
77
repository = "https://github.com/rust-embedded/embedded-hal"
88
readme = "README.md"
99
license = "MIT OR Apache-2.0"
10-
categories = [
11-
"embedded",
12-
"no-std",
13-
]
10+
categories = ["embedded", "no-std"]
1411

1512
[features]
1613
std = ["embedded-io/std"]

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)