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:
parent
7bf0a106dd
commit
783e1e81dc
|
@ -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;
|
||||
|
|
|
@ -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) }
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue