tree_table/utils/
utils_macros.rs1#[macro_export]
3macro_rules! define_struct_with_new {
4 ($struct_name:ident { $($field:ident: $ty:ty $(= $init:expr)?),* }) => {
5 #[derive(Debug)]
6 pub struct $struct_name {
7 $(pub $field: $ty),*
8 }
9
10 impl $struct_name {
11 pub fn new() -> Self {
12 $struct_name {
13 $(
14 $field: {
15 #[allow(unused_assignments)]
16 #[allow(unused_mut)]
17 {
18 let mut tmp = <$ty>::new();
19 $(tmp = $init;)?
20 tmp
21 }
22 }
23 ),*
24 }
25 }
26 }
27 };
28}
29
30#[macro_export]
32macro_rules! hm_str_key {
33 ($( $key:expr => $value:expr ),* $(,)?) => {
34 {
35 let mut map: hashbrown::HashMap<String, _> = hashbrown::HashMap::new();
36 $(
37 map.insert($key.to_string(), $value);
38 )*
39 map
40 }
41 };
42}
43
44#[macro_export]
46macro_rules! hm_str {
47 ($( $key:expr => $value:expr ),* $(,)?) => {
48 {
49 let mut map: hashbrown::HashMap<String, String> = hashbrown::HashMap::new();
50 $(
51 map.insert($key.to_string(), $value.to_string());
52 )*
53 map
54 }
55 };
56}
57
58#[macro_export]
60macro_rules! hm_raw {
61 ($( $key:expr => $value:expr ),* $(,)?) => {
62 {
63 let mut map: hashbrown::HashMap<_, _> = hashbrown::HashMap::new();
64 $(
65 map.insert($key, $value);
66 )*
67 map
68 }
69 };
70}
71
72#[macro_export]
74macro_rules! log {
75 ($lit:literal) => {
77 #[cfg(feature = "std")]
78 ::std::println!($lit);
79 };
80 ($expr:expr) => {
82 #[cfg(feature = "std")]
83 ::std::println!("{:?}", $expr);
84 };
85 ($fmt:literal, $($arg:expr),*) => {
87 #[cfg(feature = "std")]
88 ::std::println!($fmt, $($arg),*);
89 };
90 (array: $expr:expr) => {
92 #[cfg(feature = "std")]
93 ::std::println!("{:?}", $expr.collect::<Vec<_>>());
94 };
95 ($($t:tt)*) => {
97 #[cfg(feature = "std")]
98 ::std::println!($($t)*);
99 };
100}
101
102#[macro_export]
104macro_rules! str_err {
105 ($($arg:tt)*) => {
106 ::alloc::format!("Error at {}:{}: {}", file!(), line!(), ::alloc::format!($($arg)*))
107 };
108}