Merge rust-bitcoin/rust-bitcoin#1049: Implement std::error::Error for ParseAmount
5ce34011f2
Implement std::error::Error for ParseAmount (Tobin C. Harding) Pull request description: The `ParseAmountError` does not implement `std::error::Error`, must have been missed when we did the rest. Implement `std::error::Error` for `ParseAmount`. ACKs for top commit: Kixunil: ACK5ce34011f2
apoelstra: ACK5ce34011f2
Tree-SHA512: 8dafc472b7c23b54d856344e786e0f22e8e179f30f6c1011fbf5f8f0c6b1b5d74ed8e4f2638e5f8246f04dbb429e60027db6fe584d51a78957a6e904feb9e8a3
This commit is contained in:
commit
9cfa9bd9df
|
@ -185,7 +185,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')
|
||||
|
|
Loading…
Reference in New Issue