Skip to content

Commit 495fc4c

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 8a9c971 commit 495fc4c

File tree

1 file changed

+6
-10
lines changed

1 file changed

+6
-10
lines changed

src/lib.rs

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -693,18 +693,14 @@ impl fmt::Display for Error {
693693
}
694694
}
695695

696-
#[cfg(any(feature = "std", test))]
696+
#[cfg(feature = "std")]
697697
impl std::error::Error for Error {
698-
fn description(&self) -> &str {
698+
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
699+
use self::Error::*;
700+
699701
match *self {
700-
Error::MissingSeparator => "missing human-readable separator",
701-
Error::InvalidChecksum => "invalid checksum",
702-
Error::InvalidLength => "invalid length",
703-
Error::InvalidChar(_) => "invalid character",
704-
Error::InvalidData(_) => "invalid data point",
705-
Error::InvalidPadding => "invalid padding",
706-
Error::MixedCase => "mixed-case strings not allowed",
707-
Error::WriteFailure(_) => "failed writing utf-8 data",
702+
MissingSeparator | InvalidChecksum | InvalidLength | InvalidChar(_)
703+
| InvalidData(_) | InvalidPadding | MixedCase | WriteFailure(_) => None,
708704
}
709705
}
710706
}

0 commit comments

Comments
 (0)