|
1 | 1 | #[macro_export]
|
2 | 2 | macro_rules! ros_log {
|
3 |
| - ($level:expr, $($arg:tt)+) => { |
| 3 | + ($level:expr, $($arg:tt)+) => {{ |
4 | 4 | let msg = format!($($arg)*);
|
5 | 5 | $crate::log($level, msg, file!(), line!());
|
6 |
| - } |
| 6 | + }} |
7 | 7 | }
|
8 | 8 |
|
9 | 9 | #[macro_export]
|
10 | 10 | macro_rules! ros_debug {
|
11 |
| - ($($arg:tt)*) => { |
| 11 | + ($($arg:tt)*) => {{ |
12 | 12 | $crate::ros_log!($crate::msg::rosgraph_msgs::Log::DEBUG, $($arg)*);
|
13 |
| - } |
| 13 | + }} |
14 | 14 | }
|
15 | 15 |
|
16 | 16 | #[macro_export]
|
17 | 17 | macro_rules! ros_info {
|
18 |
| - ($($arg:tt)*) => { |
| 18 | + ($($arg:tt)*) => {{ |
19 | 19 | $crate::ros_log!($crate::msg::rosgraph_msgs::Log::INFO, $($arg)*);
|
20 |
| - } |
| 20 | + }} |
21 | 21 | }
|
22 | 22 |
|
23 | 23 | #[macro_export]
|
24 | 24 | macro_rules! ros_warn {
|
25 |
| - ($($arg:tt)*) => { |
| 25 | + ($($arg:tt)*) => {{ |
26 | 26 | $crate::ros_log!($crate::msg::rosgraph_msgs::Log::WARN, $($arg)*);
|
27 |
| - } |
| 27 | + }} |
28 | 28 | }
|
29 | 29 |
|
30 | 30 | #[macro_export]
|
31 | 31 | macro_rules! ros_err {
|
32 |
| - ($($arg:tt)*) => { |
| 32 | + ($($arg:tt)*) => {{ |
33 | 33 | $crate::ros_log!($crate::msg::rosgraph_msgs::Log::ERROR, $($arg)*);
|
34 |
| - } |
| 34 | + }} |
35 | 35 | }
|
36 | 36 |
|
37 | 37 | #[macro_export]
|
38 | 38 | macro_rules! ros_fatal {
|
39 |
| - ($($arg:tt)*) => { |
| 39 | + ($($arg:tt)*) => {{ |
40 | 40 | $crate::ros_log!($crate::msg::rosgraph_msgs::Log::FATAL, $($arg)*);
|
41 |
| - } |
| 41 | + }} |
42 | 42 | }
|
43 | 43 |
|
44 | 44 | #[macro_export]
|
45 | 45 | macro_rules! ros_log_once {
|
46 |
| - ($level:expr, $($arg:tt)+) => { |
| 46 | + ($level:expr, $($arg:tt)+) => {{ |
47 | 47 | let msg = format!($($arg)*);
|
48 | 48 | $crate::log_once($level, msg, file!(), line!());
|
49 |
| - } |
| 49 | + }} |
50 | 50 | }
|
51 | 51 |
|
52 | 52 | #[macro_export]
|
53 | 53 | macro_rules! ros_debug_once {
|
54 |
| - ($($arg:tt)*) => { |
| 54 | + ($($arg:tt)*) => {{ |
55 | 55 | $crate::ros_log_once!($crate::msg::rosgraph_msgs::Log::DEBUG, $($arg)*);
|
56 |
| - } |
| 56 | + }} |
57 | 57 | }
|
58 | 58 |
|
59 | 59 | #[macro_export]
|
60 | 60 | macro_rules! ros_info_once {
|
61 |
| - ($($arg:tt)*) => { |
| 61 | + ($($arg:tt)*) => {{ |
62 | 62 | $crate::ros_log_once!($crate::msg::rosgraph_msgs::Log::INFO, $($arg)*);
|
63 |
| - } |
| 63 | + }} |
64 | 64 | }
|
65 | 65 |
|
66 | 66 | #[macro_export]
|
67 | 67 | macro_rules! ros_warn_once {
|
68 |
| - ($($arg:tt)*) => { |
| 68 | + ($($arg:tt)*) => {{ |
69 | 69 | $crate::ros_log_once!($crate::msg::rosgraph_msgs::Log::WARN, $($arg)*);
|
70 |
| - } |
| 70 | + }} |
71 | 71 | }
|
72 | 72 |
|
73 | 73 | #[macro_export]
|
74 | 74 | macro_rules! ros_err_once {
|
75 |
| - ($($arg:tt)*) => { |
| 75 | + ($($arg:tt)*) => {{ |
76 | 76 | $crate::ros_log_once!($crate::msg::rosgraph_msgs::Log::ERROR, $($arg)*);
|
77 |
| - } |
| 77 | + }} |
78 | 78 | }
|
79 | 79 |
|
80 | 80 | #[macro_export]
|
81 | 81 | macro_rules! ros_fatal_once {
|
82 |
| - ($($arg:tt)*) => { |
| 82 | + ($($arg:tt)*) => {{ |
83 | 83 | $crate::ros_log_once!($crate::msg::rosgraph_msgs::Log::FATAL, $($arg)*);
|
84 |
| - } |
| 84 | + }} |
85 | 85 | }
|
86 | 86 |
|
87 | 87 | #[macro_export]
|
88 | 88 | macro_rules! ros_log_throttle {
|
89 |
| - ($period:expr, $level:expr, $($arg:tt)+) => { |
| 89 | + ($period:expr, $level:expr, $($arg:tt)+) => {{ |
90 | 90 | let msg = format!($($arg)*);
|
91 | 91 | $crate::log_throttle($period, $level, msg, file!(), line!());
|
92 |
| - } |
| 92 | + }} |
93 | 93 | }
|
94 | 94 |
|
95 | 95 | #[macro_export]
|
96 | 96 | macro_rules! ros_debug_throttle {
|
97 |
| - ($period:expr, $($arg:tt)*) => { |
| 97 | + ($period:expr, $($arg:tt)*) => {{ |
98 | 98 | $crate::ros_log_throttle!($period, $crate::msg::rosgraph_msgs::Log::DEBUG, $($arg)*);
|
99 |
| - } |
| 99 | + }} |
100 | 100 | }
|
101 | 101 |
|
102 | 102 | #[macro_export]
|
103 | 103 | macro_rules! ros_info_throttle {
|
104 |
| - ($period:expr, $($arg:tt)*) => { |
| 104 | + ($period:expr, $($arg:tt)*) => {{ |
105 | 105 | $crate::ros_log_throttle!($period, $crate::msg::rosgraph_msgs::Log::INFO, $($arg)*);
|
106 |
| - } |
| 106 | + }} |
107 | 107 | }
|
108 | 108 |
|
109 | 109 | #[macro_export]
|
110 | 110 | macro_rules! ros_warn_throttle {
|
111 |
| - ($period:expr, $($arg:tt)*) => { |
| 111 | + ($period:expr, $($arg:tt)*) => {{ |
112 | 112 | $crate::ros_log_throttle!($period, $crate::msg::rosgraph_msgs::Log::WARN, $($arg)*);
|
113 |
| - } |
| 113 | + }} |
114 | 114 | }
|
115 | 115 |
|
116 | 116 | #[macro_export]
|
117 | 117 | macro_rules! ros_err_throttle {
|
118 |
| - ($period:expr, $($arg:tt)*) => { |
| 118 | + ($period:expr, $($arg:tt)*) => {{ |
119 | 119 | $crate::ros_log_throttle!($period, $crate::msg::rosgraph_msgs::Log::ERROR, $($arg)*);
|
120 |
| - } |
| 120 | + }} |
121 | 121 | }
|
122 | 122 |
|
123 | 123 | #[macro_export]
|
124 | 124 | macro_rules! ros_fatal_throttle {
|
125 |
| - ($period:expr, $($arg:tt)*) => { |
| 125 | + ($period:expr, $($arg:tt)*) => {{ |
126 | 126 | $crate::ros_log_throttle!($period, $crate::msg::rosgraph_msgs::Log::FATAL, $($arg)*);
|
127 |
| - } |
| 127 | + }} |
128 | 128 | }
|
129 | 129 | #[macro_export]
|
130 | 130 | macro_rules! ros_log_throttle_identical {
|
131 |
| - ($period:expr, $level:expr, $($arg:tt)+) => { |
| 131 | + ($period:expr, $level:expr, $($arg:tt)+) => {{ |
132 | 132 | let msg = format!($($arg)*);
|
133 | 133 | $crate::log_throttle_identical($period, $level, msg, file!(), line!());
|
134 |
| - } |
| 134 | + }} |
135 | 135 | }
|
136 | 136 |
|
137 | 137 | #[macro_export]
|
138 | 138 | macro_rules! ros_debug_throttle_identical {
|
139 |
| - ($period:expr, $($arg:tt)*) => { |
| 139 | + ($period:expr, $($arg:tt)*) => {{ |
140 | 140 | $crate::ros_log_throttle_identical!($period, $crate::msg::rosgraph_msgs::Log::DEBUG, $($arg)*);
|
141 |
| - } |
| 141 | + }} |
142 | 142 | }
|
143 | 143 |
|
144 | 144 | #[macro_export]
|
145 | 145 | macro_rules! ros_info_throttle_identical {
|
146 |
| - ($period:expr, $($arg:tt)*) => { |
| 146 | + ($period:expr, $($arg:tt)*) => {{ |
147 | 147 | $crate::ros_log_throttle_identical!($period, $crate::msg::rosgraph_msgs::Log::INFO, $($arg)*);
|
148 |
| - } |
| 148 | + }} |
149 | 149 | }
|
150 | 150 |
|
151 | 151 | #[macro_export]
|
152 | 152 | macro_rules! ros_warn_throttle_identical {
|
153 |
| - ($period:expr, $($arg:tt)*) => { |
| 153 | + ($period:expr, $($arg:tt)*) => {{ |
154 | 154 | $crate::ros_log_throttle_identical!($period, $crate::msg::rosgraph_msgs::Log::WARN, $($arg)*);
|
155 |
| - } |
| 155 | + }} |
156 | 156 | }
|
157 | 157 |
|
158 | 158 | #[macro_export]
|
159 | 159 | macro_rules! ros_err_throttle_identical {
|
160 |
| - ($period:expr, $($arg:tt)*) => { |
| 160 | + ($period:expr, $($arg:tt)*) => {{ |
161 | 161 | $crate::ros_log_throttle_identical!($period, $crate::msg::rosgraph_msgs::Log::ERROR, $($arg)*);
|
162 |
| - } |
| 162 | + }} |
163 | 163 | }
|
164 | 164 |
|
165 | 165 | #[macro_export]
|
166 | 166 | macro_rules! ros_fatal_throttle_identical {
|
167 |
| - ($period:expr, $($arg:tt)*) => { |
| 167 | + ($period:expr, $($arg:tt)*) => {{ |
168 | 168 | $crate::ros_log_throttle_identical!($period, $crate::msg::rosgraph_msgs::Log::FATAL, $($arg)*);
|
| 169 | + }} |
| 170 | +} |
| 171 | + |
| 172 | +#[test] |
| 173 | +fn macro_in_expr_position() { |
| 174 | + match true { |
| 175 | + true => ros_info!("hello"), |
| 176 | + false => unreachable!(), |
169 | 177 | }
|
| 178 | + ros_info! {"hello"} |
| 179 | + ros_info!("hello"); |
170 | 180 | }
|
0 commit comments