Skip to content

Commit

Permalink
Update errors to current best practices
Browse files Browse the repository at this point in the history
  • Loading branch information
eldruin committed Sep 15, 2021
1 parent a724bdd commit 15f797b
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 15 deletions.
9 changes: 1 addition & 8 deletions examples/nunchuck.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,19 +40,12 @@ mod nunchuck {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match *self {
NunchuckError::Error(ref e) => fmt::Display::fmt(e, f),
NunchuckError::ParseError => fmt::Display::fmt(self.description(), f),
NunchuckError::ParseError => write!(f, "Could not parse data"),
}
}
}

impl<E: Error> Error for NunchuckError<E> {
fn description(&self) -> &str {
match *self {
NunchuckError::Error(ref e) => e.description(),
NunchuckError::ParseError => "Unable to Parse Data",
}
}

fn cause(&self) -> Option<&dyn Error> {
match *self {
NunchuckError::Error(ref e) => Some(e),
Expand Down
7 changes: 0 additions & 7 deletions src/linux.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,6 @@ impl fmt::Display for LinuxI2CError {
}

impl Error for LinuxI2CError {
fn description(&self) -> &str {
match *self {
LinuxI2CError::Io(ref e) => e.description(),
LinuxI2CError::Nix(ref e) => e.description(),
}
}

fn cause(&self) -> Option<&dyn Error> {
match *self {
LinuxI2CError::Io(ref e) => Some(e),
Expand Down

0 comments on commit 15f797b

Please sign in to comment.