diff --git a/embedded-io-adapters/src/std.rs b/embedded-io-adapters/src/std.rs index 90a2f852..cfd96d9f 100644 --- a/embedded-io-adapters/src/std.rs +++ b/embedded-io-adapters/src/std.rs @@ -40,6 +40,19 @@ impl embedded_io::Read for FromStd { fn read(&mut self, buf: &mut [u8]) -> Result { self.inner.read(buf) } + + fn read_exact( + &mut self, + buf: &mut [u8], + ) -> Result<(), embedded_io::ReadExactError> { + match self.inner.read_exact(buf) { + Ok(()) => Ok(()), + Err(error) if error.kind() == std::io::ErrorKind::UnexpectedEof => { + Err(embedded_io::ReadExactError::UnexpectedEof) + } + Err(error) => Err(error.into()), + } + } } impl embedded_io::BufRead for FromStd { @@ -105,6 +118,17 @@ impl std::io::Read for ToStd { fn read(&mut self, buf: &mut [u8]) -> Result { self.inner.read(buf).map_err(to_std_error) } + + fn read_exact(&mut self, buf: &mut [u8]) -> std::io::Result<()> { + match self.inner.read_exact(buf) { + Ok(()) => Ok(()), + Err(e @ embedded_io::ReadExactError::UnexpectedEof) => Err(std::io::Error::new( + std::io::ErrorKind::UnexpectedEof, + format!("{e:?}"), + )), + Err(embedded_io::ReadExactError::Other(e)) => Err(to_std_error(e)), + } + } } impl std::io::Write for ToStd {