pub trait SynErrorContext {
fn wrap_err(self, new: syn::Error) -> Self;
fn wrap_err_with<F>(self, f: F) -> Self
where
F: FnOnce() -> syn::Error;
}
impl<T> SynErrorContext for syn::Result<T> {
fn wrap_err(self, mut new: syn::Error) -> Self {
self.map_err(|e| {
new.combine(e);
new
})
}
fn wrap_err_with<F>(self, f: F) -> Self
where
F: FnOnce() -> syn::Error,
{
self.map_err(|e| {
let mut new = f();
new.combine(e);
new
})
}
}
impl SynErrorContext for syn::Error {
fn wrap_err(self, mut new: syn::Error) -> Self {
new.combine(self);
new
}
fn wrap_err_with<F>(self, f: F) -> Self
where
F: FnOnce() -> Self,
{
self.wrap_err(f())
}
}
#[cfg(feature = "debug-trace")]
macro_rules! debug_trace {
($($tt:tt)*) => {
{
let message = format!($($tt)*);
eprintln!("delegate_match debug @ {}:{}\t| {}", file!(), line!(), message);
}
};
}
#[cfg(not(feature = "debug-trace"))]
macro_rules! debug_trace {
($($tt:tt)*) => {
if false {
let _ = format_args!($($tt)*);
}
};
}
pub(crate) use debug_trace;