2020-12-01 16:46:56 +00:00
|
|
|
#![macro_use]
|
|
|
|
|
|
|
|
#[cfg(all(feature = "defmt", feature = "log"))]
|
|
|
|
compile_error!("You may not enable both `defmt` and `log` features.");
|
|
|
|
|
|
|
|
pub use fmt::*;
|
|
|
|
|
|
|
|
#[cfg(feature = "defmt")]
|
|
|
|
mod fmt {
|
|
|
|
pub use defmt::{
|
|
|
|
assert, assert_eq, assert_ne, debug, debug_assert, debug_assert_eq, debug_assert_ne, error,
|
|
|
|
info, panic, todo, trace, unreachable, unwrap, warn,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
#[cfg(feature = "log")]
|
|
|
|
mod fmt {
|
|
|
|
pub use core::{
|
|
|
|
assert, assert_eq, assert_ne, debug_assert, debug_assert_eq, debug_assert_ne, panic, todo,
|
|
|
|
unreachable,
|
|
|
|
};
|
|
|
|
pub use log::{debug, error, info, trace, warn};
|
|
|
|
}
|
|
|
|
|
|
|
|
#[cfg(not(any(feature = "defmt", feature = "log")))]
|
|
|
|
mod fmt {
|
|
|
|
#![macro_use]
|
|
|
|
|
|
|
|
pub use core::{
|
|
|
|
assert, assert_eq, assert_ne, debug_assert, debug_assert_eq, debug_assert_ne, panic, todo,
|
|
|
|
unreachable,
|
|
|
|
};
|
|
|
|
|
|
|
|
#[macro_export]
|
|
|
|
macro_rules! trace {
|
|
|
|
($($msg:expr),*) => {
|
|
|
|
()
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
#[macro_export]
|
|
|
|
macro_rules! debug {
|
|
|
|
($($msg:expr),*) => {
|
|
|
|
()
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
#[macro_export]
|
|
|
|
macro_rules! info {
|
|
|
|
($($msg:expr),*) => {
|
|
|
|
()
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
#[macro_export]
|
|
|
|
macro_rules! warn {
|
|
|
|
($($msg:expr),*) => {
|
|
|
|
()
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
#[macro_export]
|
|
|
|
macro_rules! error {
|
|
|
|
($($msg:expr),*) => {
|
|
|
|
()
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[cfg(not(feature = "defmt"))]
|
|
|
|
#[macro_export]
|
|
|
|
macro_rules! unwrap {
|
|
|
|
($arg:expr$(,$msg:expr)*) => {
|
|
|
|
match $crate::fmt::Try::into_result($arg) {
|
|
|
|
::core::result::Result::Ok(t) => t,
|
|
|
|
::core::result::Result::Err(e) => {
|
2020-12-01 19:00:55 +00:00
|
|
|
::core::panic!($($msg,)*);
|
2020-12-01 16:46:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Debug, Copy, Clone, Eq, PartialEq)]
|
|
|
|
pub struct NoneError;
|
|
|
|
|
|
|
|
pub trait Try {
|
|
|
|
type Ok;
|
|
|
|
type Error;
|
|
|
|
fn into_result(self) -> Result<Self::Ok, Self::Error>;
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<T> Try for Option<T> {
|
|
|
|
type Ok = T;
|
|
|
|
type Error = NoneError;
|
|
|
|
|
|
|
|
#[inline]
|
|
|
|
fn into_result(self) -> Result<T, NoneError> {
|
|
|
|
self.ok_or(NoneError)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<T, E> Try for Result<T, E> {
|
|
|
|
type Ok = T;
|
|
|
|
type Error = E;
|
|
|
|
|
|
|
|
#[inline]
|
|
|
|
fn into_result(self) -> Self {
|
|
|
|
self
|
|
|
|
}
|
|
|
|
}
|