Skip to content
This repository was archived by the owner on Nov 30, 2022. It is now read-only.

Commit 0ebe201

Browse files
committed
Implement error::Error for MSRV
Now that we have bumped the MSRV we should implement `error::Error` as it is defined for Rust 1.41.1 that means implementing `source` instead of `cause` and `description`. We only have two error types, implement `source` for both of them.
1 parent d5520c0 commit 0ebe201

File tree

1 file changed

+14
-8
lines changed

1 file changed

+14
-8
lines changed

src/impls.rs

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,17 +26,23 @@ use core2::{error, io};
2626
use crate::{Error, HashEngine, hex, sha1, sha256, sha512, ripemd160, siphash24, hmac};
2727

2828
impl error::Error for Error {
29-
#[cfg(feature = "std")]
30-
fn cause(&self) -> Option<&error::Error> { None }
31-
#[cfg(feature = "std")]
32-
fn description(&self) -> &str { "`std::error::description` is deprecated" }
29+
fn source(&self) -> Option<&(dyn error::Error + 'static)> {
30+
use Error::*;
31+
32+
match *self {
33+
InvalidLength(_, _) => None
34+
}
35+
}
3336
}
3437

3538
impl error::Error for hex::Error {
36-
#[cfg(feature = "std")]
37-
fn cause(&self) -> Option<&error::Error> { None }
38-
#[cfg(feature = "std")]
39-
fn description(&self) -> &str { "`std::error::description` is deprecated" }
39+
fn source(&self) -> Option<&(dyn error::Error + 'static)> {
40+
use hex::Error::*;
41+
42+
match *self {
43+
InvalidChar(_) | OddLengthString(_) | InvalidLength(_, _) => None
44+
}
45+
}
4046
}
4147

4248
impl<'a> io::Read for hex::HexIterator<'a> {

0 commit comments

Comments
 (0)