2023-04-30 23:19:35 +00:00
|
|
|
// SPDX-License-Identifier: CC0-1.0
|
|
|
|
|
2022-07-26 12:50:28 +00:00
|
|
|
//! Contains error types and other error handling tools.
|
|
|
|
|
|
|
|
pub use crate::parse::ParseIntError;
|
|
|
|
|
|
|
|
/// 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 {
|
2022-08-02 06:00:11 +00:00
|
|
|
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { Some(&self.$field) }
|
2022-07-26 12:50:28 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
2022-08-09 12:40:09 +00:00
|
|
|
pub(crate) use impl_std_error;
|