1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#[macro_export]
macro_rules! function {
() => {{
fn _f() {}
fn _type_name_of<T>(_: T) -> &'static str {
core::any::type_name::<T>()
}
let name = _type_name_of(_f);
&name[..name.len() - 3]
}};
}
#[macro_export]
macro_rules! short_function {
() => {{
fn f() {}
fn type_name_of<T>(_: T) -> &'static str {
core::any::type_name::<T>()
}
let name = type_name_of(f);
match &name[..name.len() - 3].rfind(':') {
Some(pos) => &name[pos + 1..name.len() - 3],
None => &name[..name.len() - 3],
}
}};
}
#[macro_export]
macro_rules! containing_function {
() => {{
fn f() {}
fn type_name_of<T>(_: T) -> &'static str {
core::any::type_name::<T>()
}
let name = type_name_of(f);
match &name[..name.len() - 3].strip_suffix("::{{closure}}") {
Some(stripped) => match &stripped.rfind(':') {
Some(pos) => &stripped[pos + 1..stripped.len()],
None => &stripped,
},
None => &name[..name.len() - 3],
}
}};
}
#[macro_export]
macro_rules! vals_str {
( $( $x:expr ),* ) => {{
let mut buffer = String::new();
$(
{
#[cfg(not(feature = "log_pretty_print"))]
{
if buffer.len() > 0 {
buffer.push_str(", ");
}
buffer.push_str(&format!("{}: {:?}", stringify!($x), $x)[..]);
}
#[cfg(feature = "log_pretty_print")] {
}
if buffer.len() > 0 {
buffer.push_str(",");
}
buffer.push_str(&format!("\n{}: {:#?}", stringify!($x), $x)[..]);
}
)*
buffer
}};
}
#[macro_export]
macro_rules! log_bytes {
($obj: expr) => {
crate::util::macro_logger::DebugBytes(&$obj)
};
}