From 316c8f1aea3c886067ad285f217da77213757927 Mon Sep 17 00:00:00 2001 From: Anders429 Date: Tue, 7 Oct 2025 10:49:16 -0600 Subject: [PATCH] Propagate lower-level errors as sources. --- embedded-io/src/lib.rs | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/embedded-io/src/lib.rs b/embedded-io/src/lib.rs index 0918cdb5..96bf9e18 100644 --- a/embedded-io/src/lib.rs +++ b/embedded-io/src/lib.rs @@ -261,7 +261,14 @@ impl fmt::Display for ReadExactError { } } -impl core::error::Error for ReadExactError {} +impl core::error::Error for ReadExactError { + fn source(&self) -> Option<&(dyn core::error::Error + 'static)> { + match self { + Self::UnexpectedEof => None, + Self::Other(error) => Some(error), + } + } +} /// Errors that could be returned by `Write` on `&mut [u8]`. #[derive(Debug, Copy, Clone, Eq, PartialEq)] @@ -294,7 +301,14 @@ impl fmt::Display for WriteFmtError { } } -impl core::error::Error for WriteFmtError {} +impl core::error::Error for WriteFmtError { + fn source(&self) -> Option<&(dyn core::error::Error + 'static)> { + match self { + Self::FmtError => None, + Self::Other(error) => Some(error), + } + } +} /// Blocking reader. ///