lightning_signer/util/
macro_logger.rs

1/// Return a long version of the function name.
2#[doc(hidden)]
3#[macro_export]
4macro_rules! function {
5    () => {{
6        fn _f() {}
7        fn _type_name_of<T>(_: T) -> &'static str {
8            core::any::type_name::<T>()
9        }
10        let name = _type_name_of(_f);
11        &name[..name.len() - 3]
12    }};
13}
14
15/// Return a shortened version of the function name.
16#[doc(hidden)]
17#[macro_export]
18macro_rules! short_function {
19    () => {{
20        fn f() {}
21        fn type_name_of<T>(_: T) -> &'static str {
22            core::any::type_name::<T>()
23        }
24        let name = type_name_of(f);
25
26        // Find and cut the rest of the path
27        match &name[..name.len() - 3].rfind(':') {
28            Some(pos) => &name[pos + 1..name.len() - 3],
29            None => &name[..name.len() - 3],
30        }
31    }};
32}
33
34/// Return a shortened version of the function name outside the closure.
35#[doc(hidden)]
36#[macro_export]
37macro_rules! containing_function {
38    () => {{
39        fn f() {}
40        fn type_name_of<T>(_: T) -> &'static str {
41            core::any::type_name::<T>()
42        }
43        let name = type_name_of(f);
44
45        // Find and cut the rest of the path
46        match &name[..name.len() - 3].strip_suffix("::{{closure}}") {
47            Some(stripped) => match &stripped.rfind(':') {
48                Some(pos) => &stripped[pos + 1..stripped.len()],
49                None => &stripped,
50            },
51            None => &name[..name.len() - 3],
52        }
53    }};
54}
55
56/// Log bytes
57#[doc(hidden)]
58#[macro_export]
59macro_rules! log_bytes {
60    ($obj: expr) => {
61        crate::util::macro_logger::DebugBytes(&$obj)
62    };
63}