summaryrefslogtreecommitdiff
path: root/examples/src/example_common.rs
diff options
context:
space:
mode:
Diffstat (limited to 'examples/src/example_common.rs')
-rw-r--r--examples/src/example_common.rs54
1 files changed, 2 insertions, 52 deletions
diff --git a/examples/src/example_common.rs b/examples/src/example_common.rs
index da753bc..3f27a0f 100644
--- a/examples/src/example_common.rs
+++ b/examples/src/example_common.rs
@@ -5,8 +5,7 @@ use nrf52840_hal as _;
use nrf_softdevice::pac;
use panic_probe as _;
-pub use defmt::{info, intern};
-
+use anyfmt::{panic, *};
use core::sync::atomic::{AtomicUsize, Ordering};
#[defmt::timestamp]
@@ -20,7 +19,7 @@ fn timestamp() -> u64 {
// Take peripherals, split by softdevice and application
pub fn take_peripherals() -> (nrf_softdevice::Peripherals, Peripherals) {
- let p = pac::Peripherals::take().dewrap();
+ let p = unwrap!(pac::Peripherals::take());
(
nrf_softdevice::Peripherals {
@@ -156,52 +155,3 @@ pub struct Peripherals {
pub USBD: pac::USBD,
pub WDT: pac::WDT,
}
-
-macro_rules! depanic {
- ($( $i:expr ),*) => {
- {
- defmt::error!($( $i ),*);
- panic!();
- }
- }
-}
-
-pub trait Dewrap<T> {
- /// dewrap = defmt unwrap
- fn dewrap(self) -> T;
-
- /// dexpect = defmt expect
- fn dexpect<M: defmt::Format>(self, msg: M) -> T;
-}
-
-impl<T> Dewrap<T> for Option<T> {
- fn dewrap(self) -> T {
- match self {
- Some(t) => t,
- None => depanic!("Dewrap failed: enum is none"),
- }
- }
-
- fn dexpect<M: defmt::Format>(self, msg: M) -> T {
- match self {
- Some(t) => t,
- None => depanic!("Unexpected None: {:?}", msg),
- }
- }
-}
-
-impl<T, E: defmt::Format> Dewrap<T> for Result<T, E> {
- fn dewrap(self) -> T {
- match self {
- Ok(t) => t,
- Err(e) => depanic!("Dewrap failed: {:?}", e),
- }
- }
-
- fn dexpect<M: defmt::Format>(self, msg: M) -> T {
- match self {
- Ok(t) => t,
- Err(e) => depanic!("Unexpected error: {:?}: {:?}", msg, e),
- }
- }
-}