Macro defmt::unwrap

unwrap!() { /* proc-macro */ }
Expand description

Unwraps an Option or Result, panicking if it is None or Err.

This macro is roughly equivalent to {Option,Result}::{expect,unwrap} but invocation looks a bit different because this is a macro and not a method. The other difference is that unwrap!-ing a Result<T, E> value requires that the error type E implements the Format trait

The following snippet shows the differences between core’s unwrap method and defmt’s unwrap macro:

use defmt::unwrap;

let x = option.unwrap();
let x = unwrap!(option);

let x = result.unwrap();
let x = unwrap!(result);

let x = value.expect("text");
let x = unwrap!(value, "text");

let x = value.expect(&format!("text {:?}", arg));
let x = unwrap!(value, "text {:?}", arg); // arg must be implement `Format`

If used, the format string must follow the defmt syntax (documented in the manual)