Skip to main content

rs_utils/
macros.rs

1//! Utility macros
2
3/// Print the stringified expression followed by its debug formatting
4pub macro show {
5  ($e:expr) => {
6    println!("{}: {:?}", stringify!($e), $e);
7  }
8}
9
10/// Print the stringified expression to stderr followed by its debug formatting
11pub macro eshow {
12  ($e:expr) => {
13    eprintln!("{}: {:?}", stringify!($e), $e);
14  }
15}
16
17/// Print the stringified expression followed by its pretty debug formatting
18pub macro pretty {
19  ($e:expr) => {
20    println!("{}: {:#?}", stringify!($e), $e);
21  }
22}
23
24/// Print the stringified expression to stderr followed by its pretty debug formatting
25pub macro epretty {
26  ($e:expr) => {
27    eprintln!("{}: {:#?}", stringify!($e), $e);
28  }
29}
30
31/// Print the stringified expression followed by its display formatting
32pub macro display {
33  ($e:expr) => {
34    println!("{}: {}", stringify!($e), $e);
35  }
36}
37
38/// Print the stringified expression to stderr followed by its display formatting
39pub macro edisplay {
40  ($e:expr) => {
41    eprintln!("{}: {}", stringify!($e), $e);
42  }
43}
44
45/// Print the stringified expression followed by its bitstring formatting
46pub macro bits {
47  ($e:expr) => {
48    let e = $e;
49    println!("{}: {:02$b}", stringify!($e), e, 8 * core::mem::size_of_val (&e));
50  }
51}
52
53/// Print the stringified expression to stderr followed by its bitstring formatting
54pub macro ebits {
55  ($e:expr) => {
56    let e = $e;
57    eprintln!("{}: {:02$b}", stringify!($e), e, 8 * core::mem::size_of_val (&e));
58  }
59}
60
61/// Print the stringified expression followed by its hexadecimal formatting
62pub macro hex {
63  ($e:expr) => {
64    println!("{}: {:x}", stringify!($e), $e);
65  }
66}
67
68/// Print the stringified expression to stderr followed by its hexadecimal formatting
69pub macro ehex {
70  ($e:expr) => {
71    println!("{}: {:x}", stringify!($e), $e);
72  }
73}
74
75/// Print the stringified expression followed by its pointer formatting
76pub macro address {
77  ($e:expr) => {
78    println!("{}: {:p}", stringify!($e), $e);
79  }
80}
81
82/// Print the stringified expression to stderr followed by its pointer formatting
83pub macro eaddress {
84  ($e:expr) => {
85    eprintln!("{}: {:p}", stringify!($e), $e);
86  }
87}