Use macro to implement `std::erorr::Error`

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.
This commit is contained in:
Martin Habovstiak 2022-07-27 20:00:18 +02:00
parent ed9012c25c
commit 86218ad240
3 changed files with 5 additions and 28 deletions

View File

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

View File

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