Better fmt macros.

This commit is contained in:
Dario Nieuwenhuis 2020-12-13 21:17:58 +01:00
parent 3be7ace878
commit 1aae27270e
2 changed files with 30 additions and 14 deletions

View File

@ -33,35 +33,35 @@ mod fmt {
#[macro_export] #[macro_export]
macro_rules! trace { macro_rules! trace {
($($msg:expr),*) => { ($($msg:expr),+ $(,)?) => {
() ()
}; };
} }
#[macro_export] #[macro_export]
macro_rules! debug { macro_rules! debug {
($($msg:expr),*) => { ($($msg:expr),+ $(,)?) => {
() ()
}; };
} }
#[macro_export] #[macro_export]
macro_rules! info { macro_rules! info {
($($msg:expr),*) => { ($($msg:expr),+ $(,)?) => {
() ()
}; };
} }
#[macro_export] #[macro_export]
macro_rules! warn { macro_rules! warn {
($($msg:expr),*) => { ($($msg:expr),+ $(,)?) => {
() ()
}; };
} }
#[macro_export] #[macro_export]
macro_rules! error { macro_rules! error {
($($msg:expr),*) => { ($($msg:expr),+ $(,)?) => {
() ()
}; };
} }
@ -70,11 +70,19 @@ mod fmt {
#[cfg(not(feature = "defmt"))] #[cfg(not(feature = "defmt"))]
#[macro_export] #[macro_export]
macro_rules! unwrap { macro_rules! unwrap {
($arg:expr$(,$msg:expr)*) => { ($arg:expr) => {
match $crate::fmt::Try::into_result($arg) { match $crate::fmt::Try::into_result($arg) {
::core::result::Result::Ok(t) => t, ::core::result::Result::Ok(t) => t,
::core::result::Result::Err(e) => { ::core::result::Result::Err(e) => {
::core::panic!($($msg,)*); ::core::panic!("unwrap of `{}` failed: {:?}", ::core::stringify!($arg), e);
}
}
};
($arg:expr, $($msg:expr),+ $(,)? ) => {
match $crate::fmt::Try::into_result($arg) {
::core::result::Result::Ok(t) => t,
::core::result::Result::Err(e) => {
::core::panic!("unwrap of `{}` failed: {}: {:?}", ::core::stringify!($arg), ::core::format_args!($($msg,)*), e);
} }
} }
} }

View File

@ -33,35 +33,35 @@ mod fmt {
#[macro_export] #[macro_export]
macro_rules! trace { macro_rules! trace {
($($msg:expr),*) => { ($($msg:expr),+ $(,)?) => {
() ()
}; };
} }
#[macro_export] #[macro_export]
macro_rules! debug { macro_rules! debug {
($($msg:expr),*) => { ($($msg:expr),+ $(,)?) => {
() ()
}; };
} }
#[macro_export] #[macro_export]
macro_rules! info { macro_rules! info {
($($msg:expr),*) => { ($($msg:expr),+ $(,)?) => {
() ()
}; };
} }
#[macro_export] #[macro_export]
macro_rules! warn { macro_rules! warn {
($($msg:expr),*) => { ($($msg:expr),+ $(,)?) => {
() ()
}; };
} }
#[macro_export] #[macro_export]
macro_rules! error { macro_rules! error {
($($msg:expr),*) => { ($($msg:expr),+ $(,)?) => {
() ()
}; };
} }
@ -70,11 +70,19 @@ mod fmt {
#[cfg(not(feature = "defmt"))] #[cfg(not(feature = "defmt"))]
#[macro_export] #[macro_export]
macro_rules! unwrap { macro_rules! unwrap {
($arg:expr$(,$msg:expr)*) => { ($arg:expr) => {
match $crate::fmt::Try::into_result($arg) { match $crate::fmt::Try::into_result($arg) {
::core::result::Result::Ok(t) => t, ::core::result::Result::Ok(t) => t,
::core::result::Result::Err(e) => { ::core::result::Result::Err(e) => {
::core::panic!($($msg,)*); ::core::panic!("unwrap of `{}` failed: {:?}", ::core::stringify!($arg), e);
}
}
};
($arg:expr, $($msg:expr),+ $(,)? ) => {
match $crate::fmt::Try::into_result($arg) {
::core::result::Result::Ok(t) => t,
::core::result::Result::Err(e) => {
::core::panic!("unwrap of `{}` failed: {}: {:?}", ::core::stringify!($arg), ::core::format_args!($($msg,)*), e);
} }
} }
} }