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.
This commit is contained in:
Martin Habovstiak 2022-09-20 12:08:06 +02:00
parent 7bf0a106dd
commit 783e1e81dc
2 changed files with 20 additions and 18 deletions

View File

@ -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;

View File

@ -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) }
}
};
}