Skip to content

Commit 2835fe1

Browse files
committed
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`.
1 parent d3c1042 commit 2835fe1

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

src/util/amount.rs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,22 @@ impl fmt::Display for ParseAmountError {
193193

194194
#[cfg(feature = "std")]
195195
#[cfg_attr(docsrs, doc(cfg(feature = "std")))]
196-
impl std::error::Error for ParseAmountError {}
196+
impl std::error::Error for ParseAmountError {
197+
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
198+
use self::ParseAmountError::*;
199+
200+
match *self {
201+
Negative
202+
| TooBig
203+
| TooPrecise
204+
| InvalidFormat
205+
| InputTooLarge
206+
| InvalidCharacter(_)
207+
| UnknownDenomination(_)
208+
| PossiblyConfusingDenomination(_) => None
209+
}
210+
}
211+
}
197212

198213
fn is_too_precise(s: &str, precision: usize) -> bool {
199214
s.contains('.') || precision >= s.len() || s.chars().rev().take(precision).any(|d| d != '0')

0 commit comments

Comments
 (0)