Skip to content

Commit 4125c4a

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 1f5ed17 commit 4125c4a

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

src/lib.rs

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -638,17 +638,19 @@ impl fmt::Display for Error {
638638
}
639639
}
640640

641-
#[cfg(any(feature = "std", test))]
641+
#[cfg(feature = "std")]
642642
impl std::error::Error for Error {
643-
fn description(&self) -> &str {
643+
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
644+
use self::Error::*;
645+
644646
match *self {
645-
Error::MissingSeparator => "missing human-readable separator",
646-
Error::InvalidChecksum => "invalid checksum",
647-
Error::InvalidLength => "invalid length",
648-
Error::InvalidChar(_) => "invalid character",
649-
Error::InvalidData(_) => "invalid data point",
650-
Error::InvalidPadding => "invalid padding",
651-
Error::MixedCase => "mixed-case strings not allowed",
647+
MissingSeparator
648+
| InvalidChecksum
649+
| InvalidLength
650+
| InvalidChar(_)
651+
| InvalidData(_)
652+
| InvalidPadding
653+
| MixedCase => None
652654
}
653655
}
654656
}

0 commit comments

Comments
 (0)