diff options
| author | Dario Nieuwenhuis <[email protected]> | 2020-12-13 21:17:58 +0100 |
|---|---|---|
| committer | Dario Nieuwenhuis <[email protected]> | 2020-12-13 21:17:58 +0100 |
| commit | 1aae27270e9cce4571bb39d8082b548a39f5c389 (patch) | |
| tree | dda4ae9209710ece6925d64c0638ae63f6ca5f3f | |
| parent | 3be7ace878a7ded8fa30709d91d358ea41cf6b49 (diff) | |
Better fmt macros.
| -rw-r--r-- | embassy-nrf/src/fmt.rs | 22 | ||||
| -rw-r--r-- | embassy/src/fmt.rs | 22 |
2 files changed, 30 insertions, 14 deletions
diff --git a/embassy-nrf/src/fmt.rs b/embassy-nrf/src/fmt.rs index 4dfba6acf..4da69766c 100644 --- a/embassy-nrf/src/fmt.rs +++ b/embassy-nrf/src/fmt.rs | |||
| @@ -33,35 +33,35 @@ mod fmt { | |||
| 33 | 33 | ||
| 34 | #[macro_export] | 34 | #[macro_export] |
| 35 | macro_rules! trace { | 35 | macro_rules! trace { |
| 36 | ($($msg:expr),*) => { | 36 | ($($msg:expr),+ $(,)?) => { |
| 37 | () | 37 | () |
| 38 | }; | 38 | }; |
| 39 | } | 39 | } |
| 40 | 40 | ||
| 41 | #[macro_export] | 41 | #[macro_export] |
| 42 | macro_rules! debug { | 42 | macro_rules! debug { |
| 43 | ($($msg:expr),*) => { | 43 | ($($msg:expr),+ $(,)?) => { |
| 44 | () | 44 | () |
| 45 | }; | 45 | }; |
| 46 | } | 46 | } |
| 47 | 47 | ||
| 48 | #[macro_export] | 48 | #[macro_export] |
| 49 | macro_rules! info { | 49 | macro_rules! info { |
| 50 | ($($msg:expr),*) => { | 50 | ($($msg:expr),+ $(,)?) => { |
| 51 | () | 51 | () |
| 52 | }; | 52 | }; |
| 53 | } | 53 | } |
| 54 | 54 | ||
| 55 | #[macro_export] | 55 | #[macro_export] |
| 56 | macro_rules! warn { | 56 | macro_rules! warn { |
| 57 | ($($msg:expr),*) => { | 57 | ($($msg:expr),+ $(,)?) => { |
| 58 | () | 58 | () |
| 59 | }; | 59 | }; |
| 60 | } | 60 | } |
| 61 | 61 | ||
| 62 | #[macro_export] | 62 | #[macro_export] |
| 63 | macro_rules! error { | 63 | macro_rules! error { |
| 64 | ($($msg:expr),*) => { | 64 | ($($msg:expr),+ $(,)?) => { |
| 65 | () | 65 | () |
| 66 | }; | 66 | }; |
| 67 | } | 67 | } |
| @@ -70,11 +70,19 @@ mod fmt { | |||
| 70 | #[cfg(not(feature = "defmt"))] | 70 | #[cfg(not(feature = "defmt"))] |
| 71 | #[macro_export] | 71 | #[macro_export] |
| 72 | macro_rules! unwrap { | 72 | macro_rules! unwrap { |
| 73 | ($arg:expr$(,$msg:expr)*) => { | 73 | ($arg:expr) => { |
| 74 | match $crate::fmt::Try::into_result($arg) { | 74 | match $crate::fmt::Try::into_result($arg) { |
| 75 | ::core::result::Result::Ok(t) => t, | 75 | ::core::result::Result::Ok(t) => t, |
| 76 | ::core::result::Result::Err(e) => { | 76 | ::core::result::Result::Err(e) => { |
| 77 | ::core::panic!($($msg,)*); | 77 | ::core::panic!("unwrap of `{}` failed: {:?}", ::core::stringify!($arg), e); |
| 78 | } | ||
| 79 | } | ||
| 80 | }; | ||
| 81 | ($arg:expr, $($msg:expr),+ $(,)? ) => { | ||
| 82 | match $crate::fmt::Try::into_result($arg) { | ||
| 83 | ::core::result::Result::Ok(t) => t, | ||
| 84 | ::core::result::Result::Err(e) => { | ||
| 85 | ::core::panic!("unwrap of `{}` failed: {}: {:?}", ::core::stringify!($arg), ::core::format_args!($($msg,)*), e); | ||
| 78 | } | 86 | } |
| 79 | } | 87 | } |
| 80 | } | 88 | } |
diff --git a/embassy/src/fmt.rs b/embassy/src/fmt.rs index 4dfba6acf..4da69766c 100644 --- a/embassy/src/fmt.rs +++ b/embassy/src/fmt.rs | |||
| @@ -33,35 +33,35 @@ mod fmt { | |||
| 33 | 33 | ||
| 34 | #[macro_export] | 34 | #[macro_export] |
| 35 | macro_rules! trace { | 35 | macro_rules! trace { |
| 36 | ($($msg:expr),*) => { | 36 | ($($msg:expr),+ $(,)?) => { |
| 37 | () | 37 | () |
| 38 | }; | 38 | }; |
| 39 | } | 39 | } |
| 40 | 40 | ||
| 41 | #[macro_export] | 41 | #[macro_export] |
| 42 | macro_rules! debug { | 42 | macro_rules! debug { |
| 43 | ($($msg:expr),*) => { | 43 | ($($msg:expr),+ $(,)?) => { |
| 44 | () | 44 | () |
| 45 | }; | 45 | }; |
| 46 | } | 46 | } |
| 47 | 47 | ||
| 48 | #[macro_export] | 48 | #[macro_export] |
| 49 | macro_rules! info { | 49 | macro_rules! info { |
| 50 | ($($msg:expr),*) => { | 50 | ($($msg:expr),+ $(,)?) => { |
| 51 | () | 51 | () |
| 52 | }; | 52 | }; |
| 53 | } | 53 | } |
| 54 | 54 | ||
| 55 | #[macro_export] | 55 | #[macro_export] |
| 56 | macro_rules! warn { | 56 | macro_rules! warn { |
| 57 | ($($msg:expr),*) => { | 57 | ($($msg:expr),+ $(,)?) => { |
| 58 | () | 58 | () |
| 59 | }; | 59 | }; |
| 60 | } | 60 | } |
| 61 | 61 | ||
| 62 | #[macro_export] | 62 | #[macro_export] |
| 63 | macro_rules! error { | 63 | macro_rules! error { |
| 64 | ($($msg:expr),*) => { | 64 | ($($msg:expr),+ $(,)?) => { |
| 65 | () | 65 | () |
| 66 | }; | 66 | }; |
| 67 | } | 67 | } |
| @@ -70,11 +70,19 @@ mod fmt { | |||
| 70 | #[cfg(not(feature = "defmt"))] | 70 | #[cfg(not(feature = "defmt"))] |
| 71 | #[macro_export] | 71 | #[macro_export] |
| 72 | macro_rules! unwrap { | 72 | macro_rules! unwrap { |
| 73 | ($arg:expr$(,$msg:expr)*) => { | 73 | ($arg:expr) => { |
| 74 | match $crate::fmt::Try::into_result($arg) { | 74 | match $crate::fmt::Try::into_result($arg) { |
| 75 | ::core::result::Result::Ok(t) => t, | 75 | ::core::result::Result::Ok(t) => t, |
| 76 | ::core::result::Result::Err(e) => { | 76 | ::core::result::Result::Err(e) => { |
| 77 | ::core::panic!($($msg,)*); | 77 | ::core::panic!("unwrap of `{}` failed: {:?}", ::core::stringify!($arg), e); |
| 78 | } | ||
| 79 | } | ||
| 80 | }; | ||
| 81 | ($arg:expr, $($msg:expr),+ $(,)? ) => { | ||
| 82 | match $crate::fmt::Try::into_result($arg) { | ||
| 83 | ::core::result::Result::Ok(t) => t, | ||
| 84 | ::core::result::Result::Err(e) => { | ||
| 85 | ::core::panic!("unwrap of `{}` failed: {}: {:?}", ::core::stringify!($arg), ::core::format_args!($($msg,)*), e); | ||
| 78 | } | 86 | } |
| 79 | } | 87 | } |
| 80 | } | 88 | } |
