#[macro_export]
macro_rules! diagnostic_from {
($error:ty, |$value:ident| $code:expr) => {
$crate::diagnostic_from!($error, |$value| $code, |diagnostic, _error| diagnostic);
};
($error:ty, |$value:ident| $code:expr, |$diagnostic:ident, $inner:ident| $context:expr) => {
impl ::core::convert::From<&$error> for $crate::Diagnostic {
fn from($value: &$error) -> Self {
let code: $crate::Code = $code;
let $diagnostic = $crate::Diagnostic::new(code)
.with_message(::std::string::ToString::to_string($value));
let $inner = $value;
$context
}
}
impl ::core::convert::From<$error> for $crate::Diagnostic {
fn from(value: $error) -> Self {
Self::from(&value)
}
}
};
}
impl From<&std::convert::Infallible> for crate::Diagnostic {
fn from(never: &std::convert::Infallible) -> Self {
match *never {}
}
}
impl From<&crate::Diagnostic> for crate::Diagnostic {
fn from(diagnostic: &crate::Diagnostic) -> Self {
diagnostic.clone()
}
}