honeyholt/macro/brief/
mod.rs1#[macro_export]
3macro_rules! honeyholt_define_brief {
4 ($struct_name: ident, $impl: expr) => {
5 use honeyholt::r#trait::brief::Brief;
6 use std::fmt;
7 impl Brief for $struct_name {
8 fn honeyholt_display_brief<'a>(&'a self) -> Box<dyn fmt::Display + 'a> {
9 struct MyDisplay<'a>(pub &'a $struct_name);
10 impl<'a> fmt::Display for MyDisplay<'a> {
11 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
12 write!(f, "{}", ($impl)(self.0))
13 }
14 }
15 Box::new(MyDisplay(self))
16 }
17 }
18 };
19}
20
21#[macro_export]
23macro_rules! honeyholt_brief {
24 ($var: expr) => {{
25 use honeyholt::r#trait::brief::Brief;
26 format!("{}", $var.honeyholt_display_brief())
27 }};
28}