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:
    ACK 5ce34011f2
  apoelstra:
    ACK 5ce34011f2

Tree-SHA512: 8dafc472b7c23b54d856344e786e0f22e8e179f30f6c1011fbf5f8f0c6b1b5d74ed8e4f2638e5f8246f04dbb429e60027db6fe584d51a78957a6e904feb9e8a3
This commit is contained in:
Andrew Poelstra 2022-07-14 13:24:12 +00:00
commit 9cfa9bd9df
No known key found for this signature in database
GPG Key ID: C588D63CE41B97C1
1 changed files with 16 additions and 1 deletions

View File

@ -185,7 +185,22 @@ impl fmt::Display for ParseAmountError {
#[cfg(feature = "std")] #[cfg(feature = "std")]
#[cfg_attr(docsrs, doc(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 { fn is_too_precise(s: &str, precision: usize) -> bool {
s.contains('.') || precision >= s.len() || s.chars().rev().take(precision).any(|d| d != '0') s.contains('.') || precision >= s.len() || s.chars().rev().take(precision).any(|d| d != '0')