Merge rust-bitcoin/rust-bitcoin#1136: Impl std error using macro

86218ad240 Use macro to implement `std::erorr::Error` (Martin Habovstiak)

Pull request description:

  There was a bunch of manual implemntations that can be converted to
  macro call. This commit replaces them except for enums because those are
  currently not supported by the macro and we want to protect against
  forgetting to handle newly added variants.

  Depends on #1129 and is **not** urgent for the next release.

ACKs for top commit:
  apoelstra:
    ACK 86218ad240
  tcharding:
    ACK 86218ad240

Tree-SHA512: a4ca91e023d66b5ad9408004b201cfe4cea85efb5a6e7f2241367934a954659c9196561295a491d2b2ed15c1a69c0ffb17a297d710cec4ce1d0f1ec8c12492e6
This commit is contained in:
Andrew Poelstra 2022-09-09 00:32:27 +00:00
commit 816d24e385
No known key found for this signature in database
GPG Key ID: C588D63CE41B97C1
3 changed files with 5 additions and 28 deletions

View File

@ -156,13 +156,7 @@ impl fmt::Display for CommandStringError {
}
}
#[cfg(feature = "std")]
#[cfg_attr(docsrs, doc(cfg(feature = "std")))]
impl std::error::Error for CommandStringError {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
None
}
}
crate::error::impl_std_error!(CommandStringError);
/// A Network message
#[derive(Clone, Debug, PartialEq, Eq)]

View File

@ -16,6 +16,7 @@ use crate::{io, Script, Transaction, TxIn, TxOut, Sequence, Sighash};
use crate::blockdata::transaction::EncodeSigningDataResult;
use crate::blockdata::witness::Witness;
use crate::consensus::{encode, Encodable};
use crate::error::impl_std_error;
use crate::util::endian;
use crate::hashes::{sha256, sha256d, Hash};
use crate::internal_macros::serde_string_impl;
@ -488,13 +489,7 @@ impl fmt::Display for NonStandardSighashType {
}
}
#[cfg(feature = "std")]
#[cfg_attr(docsrs, doc(cfg(feature = "std")))]
impl std::error::Error for NonStandardSighashType {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
None
}
}
impl_std_error!(NonStandardSighashType);
/// Error returned for failure during parsing one of the sighash types.
///
@ -511,13 +506,7 @@ impl fmt::Display for SighashTypeParseError {
}
}
#[cfg(feature = "std")]
#[cfg_attr(docsrs, doc(cfg(feature = "std")))]
impl std::error::Error for SighashTypeParseError {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
None
}
}
impl_std_error!(SighashTypeParseError);
impl<R: Deref<Target = Transaction>> SighashCache<R> {
/// Constructs a new `SighashCache` from an unsigned transaction.

View File

@ -521,13 +521,7 @@ impl core::fmt::Display for ParseLengthError {
}
}
#[cfg(feature = "std")]
#[cfg_attr(docsrs, doc(cfg(feature = "std")))]
impl std::error::Error for ParseLengthError {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
None
}
}
crate::error::impl_std_error!(ParseLengthError);
impl Uint256 {
/// Decay to a uint128