ombrac_netstack/
macros.rs

1#[macro_export]
2macro_rules! trace {
3    ($fmt:expr $(, $args:expr)*) => {
4        #[cfg(debug_assertions)]
5        #[cfg(feature = "tracing")]
6        {
7            tracing::trace!($fmt $(, $args)*);
8        }
9    };
10}
11
12#[macro_export]
13macro_rules! debug {
14    ($fmt:expr $(, $args:expr)*) => {
15        #[cfg(debug_assertions)]
16        #[cfg(feature = "tracing")]
17        {
18            tracing::debug!($fmt $(, $args)*);
19        }
20    };
21}
22
23#[macro_export]
24macro_rules! info {
25    ($fmt:expr $(, $args:expr)*) => {
26        #[cfg(feature = "tracing")]
27        {
28            tracing::info!($fmt $(, $args)*);
29        }
30    };
31}
32
33#[macro_export]
34macro_rules! warn {
35    ($fmt:expr $(, $args:expr)*) => {
36        #[cfg(feature = "tracing")]
37        {
38            tracing::warn!($fmt $(, $args)*);
39        }
40    };
41}
42
43#[macro_export]
44macro_rules! error {
45    ($fmt:expr $(, $args:expr)*) => {
46        #[cfg(feature = "tracing")]
47        {
48            tracing::error!($fmt $(, $args)*);
49        }
50    };
51}
52
53#[macro_export]
54macro_rules! try_or_continue {
55    ($expr:expr) => {
56        match $expr {
57            Ok(value) => value,
58            Err(_error) => {
59                #[cfg(feature = "tracing")]
60                {
61                    tracing::error!("{}", _error);
62                }
63
64                continue;
65            }
66        }
67    };
68}
69
70#[macro_export]
71macro_rules! try_or_break {
72    ($expr:expr) => {
73        match $expr {
74            Ok(value) => value,
75            Err(_error) => {
76                #[cfg(feature = "tracing")]
77                {
78                    tracing::error!("{}", _error);
79                }
80
81                break;
82            }
83        }
84    };
85}
86
87#[macro_export]
88macro_rules! try_or_return {
89    ($expr:expr) => {
90        match $expr {
91            Ok(value) => value,
92            Err(_error) => {
93                #[cfg(feature = "tracing")]
94                {
95                    tracing::error!("{}", _error);
96                }
97
98                return;
99            }
100        }
101    };
102}
103
104#[macro_export]
105macro_rules! debug_timer {
106    ($name:expr, $body:expr) => {{
107        #[cfg(debug_assertions)]
108        #[cfg(feature = "tracing")]
109        let start = std::time::Instant::now();
110
111        let result = $body;
112
113        #[cfg(debug_assertions)]
114        #[cfg(feature = "tracing")]
115        tracing::debug!("{} {:?}", $name, start.elapsed());
116
117        result
118    }};
119}