From 783e1e81dcf2ccc601c1615277386f1b10ab6cc2 Mon Sep 17 00:00:00 2001 From: Martin Habovstiak Date: Tue, 20 Sep 2022 12:08:06 +0200 Subject: [PATCH] Move `impl_std_error` to `bitcoin-internals` The macro is useful for all other crates thus it is moved to the internals crate in this commit. --- bitcoin/src/error.rs | 20 ++------------------ internals/src/error.rs | 18 ++++++++++++++++++ 2 files changed, 20 insertions(+), 18 deletions(-) diff --git a/bitcoin/src/error.rs b/bitcoin/src/error.rs index 0536c72f..ab296628 100644 --- a/bitcoin/src/error.rs +++ b/bitcoin/src/error.rs @@ -2,22 +2,6 @@ //! Contains error types and other error handling tools. -pub use crate::parse::ParseIntError; +pub(crate) use internals::impl_std_error; -/// Impls std::error::Error for the specified type with appropriate attributes, possibly returning -/// source. -macro_rules! impl_std_error { - // No source available - ($type:ty) => { - #[cfg(feature = "std")] - impl std::error::Error for $type {} - }; - // Struct with $field as source - ($type:ty, $field:ident) => { - #[cfg(feature = "std")] - impl std::error::Error for $type { - fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { Some(&self.$field) } - } - }; -} -pub(crate) use impl_std_error; +pub use crate::parse::ParseIntError; diff --git a/internals/src/error.rs b/internals/src/error.rs index ff596734..d6049fbd 100644 --- a/internals/src/error.rs +++ b/internals/src/error.rs @@ -26,3 +26,21 @@ macro_rules! write_err { } } } + +/// Impls std::error::Error for the specified type with appropriate attributes, possibly returning +/// source. +#[macro_export] +macro_rules! impl_std_error { + // No source available + ($type:ty) => { + #[cfg(feature = "std")] + impl std::error::Error for $type {} + }; + // Struct with $field as source + ($type:ty, $field:ident) => { + #[cfg(feature = "std")] + impl std::error::Error for $type { + fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { Some(&self.$field) } + } + }; +}