Skip to content

Commit ae9f18a

Browse files
committed
Merge #72: Implement std::error::Error::source
5b520d0 Implement std::error::Error::source (Tobin C. Harding) 6052c60 Add full stops to error rustdocs (Tobin C. Harding) Pull request description: Now that we have MSRV of 1.41.1 we can implement `source` to improve the ergonomics of our errors. Patch 1 is preparatory cleanup. ACKs for top commit: apoelstra: ACK 5b520d0 Tree-SHA512: e39b90295c3b030090a79c82f7c3bb94aae0e97600fcb54092979e5320cffd490ee54af8af95f104d092a9ba8bffec2b2101c17e91ffd4494593462ddf1c95c6
2 parents d12513f + 5b520d0 commit ae9f18a

File tree

1 file changed

+14
-17
lines changed

1 file changed

+14
-17
lines changed

src/lib.rs

+14-17
Original file line numberDiff line numberDiff line change
@@ -659,22 +659,22 @@ const GEN: [u32; 5] = [
659659
0x2a14_62b3,
660660
];
661661

662-
/// Error types for Bech32 encoding / decoding
662+
/// Error types for Bech32 encoding / decoding.
663663
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)]
664664
pub enum Error {
665-
/// String does not contain the separator character
665+
/// String does not contain the separator character.
666666
MissingSeparator,
667-
/// The checksum does not match the rest of the data
667+
/// The checksum does not match the rest of the data.
668668
InvalidChecksum,
669-
/// The data or human-readable part is too long or too short
669+
/// The data or human-readable part is too long or too short.
670670
InvalidLength,
671-
/// Some part of the string contains an invalid character
671+
/// Some part of the string contains an invalid character.
672672
InvalidChar(char),
673-
/// Some part of the data has an invalid value
673+
/// Some part of the data has an invalid value.
674674
InvalidData(u8),
675-
/// The bit conversion failed due to a padding issue
675+
/// The bit conversion failed due to a padding issue.
676676
InvalidPadding,
677-
/// The whole string must be of one case
677+
/// The whole string must be of one case.
678678
MixedCase,
679679
}
680680

@@ -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)