diff options
| author | Dario Nieuwenhuis <[email protected]> | 2021-06-07 00:10:54 +0200 |
|---|---|---|
| committer | Dario Nieuwenhuis <[email protected]> | 2021-06-07 00:16:39 +0200 |
| commit | e7dc5c0939d30ccba98418c42799c4e39f646d23 (patch) | |
| tree | 896ebf078e97f15443dd85342f498231e142f975 /embassy-net/src/fmt.rs | |
| parent | 4dda7be96841430c3aed2f014644b0b65cff0ef2 (diff) | |
fmt: make all macros `macro_rules` so scoping is consistent.
Diffstat (limited to 'embassy-net/src/fmt.rs')
| -rw-r--r-- | embassy-net/src/fmt.rs | 195 |
1 files changed, 146 insertions, 49 deletions
diff --git a/embassy-net/src/fmt.rs b/embassy-net/src/fmt.rs index 4da69766c..6c5063f7c 100644 --- a/embassy-net/src/fmt.rs +++ b/embassy-net/src/fmt.rs | |||
| @@ -1,74 +1,171 @@ | |||
| 1 | #![macro_use] | 1 | #![macro_use] |
| 2 | #![allow(unused_macros)] | ||
| 2 | 3 | ||
| 3 | #[cfg(all(feature = "defmt", feature = "log"))] | 4 | #[cfg(all(feature = "defmt", feature = "log"))] |
| 4 | compile_error!("You may not enable both `defmt` and `log` features."); | 5 | compile_error!("You may not enable both `defmt` and `log` features."); |
| 5 | 6 | ||
| 6 | pub use fmt::*; | 7 | macro_rules! assert { |
| 8 | ($($x:tt)*) => { | ||
| 9 | { | ||
| 10 | #[cfg(not(feature = "defmt"))] | ||
| 11 | core::assert!($($x)*); | ||
| 12 | #[cfg(feature = "defmt")] | ||
| 13 | defmt::assert!($($x)*); | ||
| 14 | } | ||
| 15 | }; | ||
| 16 | } | ||
| 7 | 17 | ||
| 8 | #[cfg(feature = "defmt")] | 18 | macro_rules! assert_eq { |
| 9 | mod fmt { | 19 | ($($x:tt)*) => { |
| 10 | pub use defmt::{ | 20 | { |
| 11 | assert, assert_eq, assert_ne, debug, debug_assert, debug_assert_eq, debug_assert_ne, error, | 21 | #[cfg(not(feature = "defmt"))] |
| 12 | info, panic, todo, trace, unreachable, unwrap, warn, | 22 | core::assert_eq!($($x)*); |
| 23 | #[cfg(feature = "defmt")] | ||
| 24 | defmt::assert_eq!($($x)*); | ||
| 25 | } | ||
| 13 | }; | 26 | }; |
| 14 | } | 27 | } |
| 15 | 28 | ||
| 16 | #[cfg(feature = "log")] | 29 | macro_rules! assert_ne { |
| 17 | mod fmt { | 30 | ($($x:tt)*) => { |
| 18 | pub use core::{ | 31 | { |
| 19 | assert, assert_eq, assert_ne, debug_assert, debug_assert_eq, debug_assert_ne, panic, todo, | 32 | #[cfg(not(feature = "defmt"))] |
| 20 | unreachable, | 33 | core::assert_ne!($($x)*); |
| 34 | #[cfg(feature = "defmt")] | ||
| 35 | defmt::assert_ne!($($x)*); | ||
| 36 | } | ||
| 21 | }; | 37 | }; |
| 22 | pub use log::{debug, error, info, trace, warn}; | ||
| 23 | } | 38 | } |
| 24 | 39 | ||
| 25 | #[cfg(not(any(feature = "defmt", feature = "log")))] | 40 | macro_rules! debug_assert { |
| 26 | mod fmt { | 41 | ($($x:tt)*) => { |
| 27 | #![macro_use] | 42 | { |
| 43 | #[cfg(not(feature = "defmt"))] | ||
| 44 | core::debug_assert!($($x)*); | ||
| 45 | #[cfg(feature = "defmt")] | ||
| 46 | defmt::debug_assert!($($x)*); | ||
| 47 | } | ||
| 48 | }; | ||
| 49 | } | ||
| 28 | 50 | ||
| 29 | pub use core::{ | 51 | macro_rules! debug_assert_eq { |
| 30 | assert, assert_eq, assert_ne, debug_assert, debug_assert_eq, debug_assert_ne, panic, todo, | 52 | ($($x:tt)*) => { |
| 31 | unreachable, | 53 | { |
| 54 | #[cfg(not(feature = "defmt"))] | ||
| 55 | core::debug_assert_eq!($($x)*); | ||
| 56 | #[cfg(feature = "defmt")] | ||
| 57 | defmt::debug_assert_eq!($($x)*); | ||
| 58 | } | ||
| 32 | }; | 59 | }; |
| 60 | } | ||
| 33 | 61 | ||
| 34 | #[macro_export] | 62 | macro_rules! debug_assert_ne { |
| 35 | macro_rules! trace { | 63 | ($($x:tt)*) => { |
| 36 | ($($msg:expr),+ $(,)?) => { | 64 | { |
| 37 | () | 65 | #[cfg(not(feature = "defmt"))] |
| 38 | }; | 66 | core::debug_assert_ne!($($x)*); |
| 39 | } | 67 | #[cfg(feature = "defmt")] |
| 68 | defmt::debug_assert_ne!($($x)*); | ||
| 69 | } | ||
| 70 | }; | ||
| 71 | } | ||
| 40 | 72 | ||
| 41 | #[macro_export] | 73 | macro_rules! todo { |
| 42 | macro_rules! debug { | 74 | ($($x:tt)*) => { |
| 43 | ($($msg:expr),+ $(,)?) => { | 75 | { |
| 44 | () | 76 | #[cfg(not(feature = "defmt"))] |
| 45 | }; | 77 | core::todo!($($x)*); |
| 46 | } | 78 | #[cfg(feature = "defmt")] |
| 79 | defmt::todo!($($x)*); | ||
| 80 | } | ||
| 81 | }; | ||
| 82 | } | ||
| 47 | 83 | ||
| 48 | #[macro_export] | 84 | macro_rules! unreachable { |
| 49 | macro_rules! info { | 85 | ($($x:tt)*) => { |
| 50 | ($($msg:expr),+ $(,)?) => { | 86 | { |
| 51 | () | 87 | #[cfg(not(feature = "defmt"))] |
| 52 | }; | 88 | core::unreachable!($($x)*); |
| 53 | } | 89 | #[cfg(feature = "defmt")] |
| 90 | defmt::unreachable!($($x)*); | ||
| 91 | } | ||
| 92 | }; | ||
| 93 | } | ||
| 54 | 94 | ||
| 55 | #[macro_export] | 95 | macro_rules! panic { |
| 56 | macro_rules! warn { | 96 | ($($x:tt)*) => { |
| 57 | ($($msg:expr),+ $(,)?) => { | 97 | { |
| 58 | () | 98 | #[cfg(not(feature = "defmt"))] |
| 59 | }; | 99 | core::panic!($($x)*); |
| 60 | } | 100 | #[cfg(feature = "defmt")] |
| 101 | defmt::panic!($($x)*); | ||
| 102 | } | ||
| 103 | }; | ||
| 104 | } | ||
| 61 | 105 | ||
| 62 | #[macro_export] | 106 | macro_rules! trace { |
| 63 | macro_rules! error { | 107 | ($($x:tt)*) => { |
| 64 | ($($msg:expr),+ $(,)?) => { | 108 | { |
| 65 | () | 109 | #[cfg(feature = "log")] |
| 66 | }; | 110 | log::trace!($($x)*); |
| 67 | } | 111 | #[cfg(feature = "defmt")] |
| 112 | defmt::trace!($($x)*); | ||
| 113 | } | ||
| 114 | }; | ||
| 115 | } | ||
| 116 | |||
| 117 | macro_rules! debug { | ||
| 118 | ($($x:tt)*) => { | ||
| 119 | { | ||
| 120 | #[cfg(fevature = "log")] | ||
| 121 | log::debug!($($x)*); | ||
| 122 | #[cfg(feature = "defmt")] | ||
| 123 | defmt::debug!($($x)*); | ||
| 124 | } | ||
| 125 | }; | ||
| 126 | } | ||
| 127 | |||
| 128 | macro_rules! info { | ||
| 129 | ($($x:tt)*) => { | ||
| 130 | { | ||
| 131 | #[cfg(feature = "log")] | ||
| 132 | log::info!($($x)*); | ||
| 133 | #[cfg(feature = "defmt")] | ||
| 134 | defmt::info!($($x)*); | ||
| 135 | } | ||
| 136 | }; | ||
| 137 | } | ||
| 138 | |||
| 139 | macro_rules! warn { | ||
| 140 | ($($x:tt)*) => { | ||
| 141 | { | ||
| 142 | #[cfg(feature = "log")] | ||
| 143 | log::warn!($($x)*); | ||
| 144 | #[cfg(feature = "defmt")] | ||
| 145 | defmt::warn!($($x)*); | ||
| 146 | } | ||
| 147 | }; | ||
| 148 | } | ||
| 149 | |||
| 150 | macro_rules! error { | ||
| 151 | ($($x:tt)*) => { | ||
| 152 | { | ||
| 153 | #[cfg(feature = "log")] | ||
| 154 | log::error!($($x)*); | ||
| 155 | #[cfg(feature = "defmt")] | ||
| 156 | defmt::error!($($x)*); | ||
| 157 | } | ||
| 158 | }; | ||
| 159 | } | ||
| 160 | |||
| 161 | #[cfg(feature = "defmt")] | ||
| 162 | macro_rules! unwrap { | ||
| 163 | ($($x:tt)*) => { | ||
| 164 | defmt::unwrap!($($x)*) | ||
| 165 | }; | ||
| 68 | } | 166 | } |
| 69 | 167 | ||
| 70 | #[cfg(not(feature = "defmt"))] | 168 | #[cfg(not(feature = "defmt"))] |
| 71 | #[macro_export] | ||
| 72 | macro_rules! unwrap { | 169 | macro_rules! unwrap { |
| 73 | ($arg:expr) => { | 170 | ($arg:expr) => { |
| 74 | match $crate::fmt::Try::into_result($arg) { | 171 | match $crate::fmt::Try::into_result($arg) { |
