From 5ce34011f2006442e8d2c09cb446aacf9debd31b Mon Sep 17 00:00:00 2001 From: "Tobin C. Harding" Date: Fri, 10 Jun 2022 12:07:46 +1000 Subject: [PATCH] Implement std::error::Error for ParseAmount The `ParseAmountError` does not implement `std::error::Error`, must have been missed when we did the rest. Implement `std::error::Error` for `ParseAmount`. --- src/util/amount.rs | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/util/amount.rs b/src/util/amount.rs index e2eff86b..0752608d 100644 --- a/src/util/amount.rs +++ b/src/util/amount.rs @@ -193,7 +193,22 @@ impl fmt::Display for ParseAmountError { #[cfg(feature = "std")] #[cfg_attr(docsrs, doc(cfg(feature = "std")))] -impl std::error::Error for ParseAmountError {} +impl std::error::Error for ParseAmountError { + fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { + use self::ParseAmountError::*; + + match *self { + Negative + | TooBig + | TooPrecise + | InvalidFormat + | InputTooLarge + | InvalidCharacter(_) + | UnknownDenomination(_) + | PossiblyConfusingDenomination(_) => None + } + } +} fn is_too_precise(s: &str, precision: usize) -> bool { s.contains('.') || precision >= s.len() || s.chars().rev().take(precision).any(|d| d != '0')