macro_rules! impl_function_debug_display {
($struct_name:ident < $t:ident, $r:ident >) => {
impl<$t, $r> std::fmt::Debug for $struct_name<$t, $r> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct(stringify!($struct_name))
.field("name", &self.name)
.field("function", &"<function>")
.finish()
}
}
impl<$t, $r> std::fmt::Display for $struct_name<$t, $r> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match &self.name {
Some(name) => write!(f, "{}({})", stringify!($struct_name), name),
None => write!(f, "{}", stringify!($struct_name)),
}
}
}
};
($struct_name:ident < $t:ident, $u:ident, $r:ident >) => {
impl<$t, $u, $r> std::fmt::Debug for $struct_name<$t, $u, $r> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct(stringify!($struct_name))
.field("name", &self.name)
.field("function", &"<function>")
.finish()
}
}
impl<$t, $u, $r> std::fmt::Display for $struct_name<$t, $u, $r> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match &self.name {
Some(name) => write!(f, "{}({})", stringify!($struct_name), name),
None => write!(f, "{}", stringify!($struct_name)),
}
}
}
};
}
pub(crate) use impl_function_debug_display;