Skip to content

Commit

Permalink
Add a NoDetails variant for MockError
Browse files Browse the repository at this point in the history
This allows the creation of errors without any details and removes the dependency on `std` just for errors.
  • Loading branch information
cdunster committed Nov 16, 2023
1 parent ec4b93b commit cc1381a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/eh0/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ use std::{error::Error as StdError, fmt, io};
/// Errors that may occur during mocking.
#[derive(PartialEq, Eq, Clone, Debug)]
pub enum MockError {
/// An error occurred without any details.
NoDetails,

/// An I/O-Error occurred
Io(io::ErrorKind),
}
Expand All @@ -16,6 +19,7 @@ impl From<io::Error> for MockError {
impl fmt::Display for MockError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
MockError::NoDetails => write!(f, "An error occurred without any details"),
MockError::Io(kind) => write!(f, "I/O error: {:?}", kind),
}
}
Expand Down
4 changes: 4 additions & 0 deletions src/eh1/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ use embedded_hal::digital::ErrorKind::{self, Other};
/// Errors that may occur during mocking.
#[derive(PartialEq, Eq, Clone, Debug)]
pub enum MockError {
/// An error occurred without any details.
NoDetails,

/// An I/O-Error occurred
Io(io::ErrorKind),
}
Expand All @@ -25,6 +28,7 @@ impl From<io::Error> for MockError {
impl fmt::Display for MockError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
MockError::NoDetails => write!(f, "An error occurred without any details"),
MockError::Io(kind) => write!(f, "I/O error: {:?}", kind),
}
}
Expand Down

0 comments on commit cc1381a

Please sign in to comment.