#[macro_export]
macro_rules! parse_error_type {
($vis:vis $name:ident, $source:ty, $subject:expr $(, $derive:path)* $(,)?) => {
#[derive(Debug $(, $derive)*)]
$vis struct $name {
input: $crate::error::InputString,
source: $source,
}
impl $name {
fn new<T: Into<$crate::error::InputString>>(input: T, source: $source) -> Self {
$name {
input: input.into(),
source,
}
}
}
impl core::fmt::Display for $name {
fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
$crate::error::write_err!(f, "{}", self.input.display_cannot_parse($subject); self.source)
}
}
#[cfg(feature = "std")]
impl std::error::Error for $name {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { Some(&self.source) }
}
}
}