Skip to content

Commit 5b520d0

Browse files
committed
Implement std::error::Error::source
Now that we have MSRV of 1.41.1 we can implement `source` to improve the ergonomics of our errors.
1 parent 6052c60 commit 5b520d0

File tree

1 file changed

+6
-9
lines changed

1 file changed

+6
-9
lines changed

src/lib.rs

+6-9
Original file line numberDiff line numberDiff line change
@@ -692,17 +692,14 @@ impl fmt::Display for Error {
692692
}
693693
}
694694

695-
#[cfg(any(feature = "std", test))]
695+
#[cfg(feature = "std")]
696696
impl std::error::Error for Error {
697-
fn description(&self) -> &str {
697+
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
698+
use self::Error::*;
699+
698700
match *self {
699-
Error::MissingSeparator => "missing human-readable separator",
700-
Error::InvalidChecksum => "invalid checksum",
701-
Error::InvalidLength => "invalid length",
702-
Error::InvalidChar(_) => "invalid character",
703-
Error::InvalidData(_) => "invalid data point",
704-
Error::InvalidPadding => "invalid padding",
705-
Error::MixedCase => "mixed-case strings not allowed",
701+
MissingSeparator | InvalidChecksum | InvalidLength | InvalidChar(_)
702+
| InvalidData(_) | InvalidPadding | MixedCase => None,
706703
}
707704
}
708705
}

0 commit comments

Comments
 (0)