Skip to content

Commit fbb5c79

Browse files
authored
Merge pull request #712 from Anders429/error-source
Propagate lower-level errors as sources for embedded_io error types.
2 parents c4c1077 + 316c8f1 commit fbb5c79

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

embedded-io/src/lib.rs

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,14 @@ impl<E: fmt::Debug> fmt::Display for ReadExactError<E> {
261261
}
262262
}
263263

264-
impl<E: fmt::Debug> core::error::Error for ReadExactError<E> {}
264+
impl<E: core::error::Error + 'static> core::error::Error for ReadExactError<E> {
265+
fn source(&self) -> Option<&(dyn core::error::Error + 'static)> {
266+
match self {
267+
Self::UnexpectedEof => None,
268+
Self::Other(error) => Some(error),
269+
}
270+
}
271+
}
265272

266273
/// Errors that could be returned by `Write` on `&mut [u8]`.
267274
#[derive(Debug, Copy, Clone, Eq, PartialEq)]
@@ -294,7 +301,14 @@ impl<E: fmt::Debug> fmt::Display for WriteFmtError<E> {
294301
}
295302
}
296303

297-
impl<E: fmt::Debug> core::error::Error for WriteFmtError<E> {}
304+
impl<E: core::error::Error + 'static> core::error::Error for WriteFmtError<E> {
305+
fn source(&self) -> Option<&(dyn core::error::Error + 'static)> {
306+
match self {
307+
Self::FmtError => None,
308+
Self::Other(error) => Some(error),
309+
}
310+
}
311+
}
298312

299313
/// Blocking reader.
300314
///

0 commit comments

Comments
 (0)