Macro 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 = result.expect("text");
let x = unwrap!(result, "text");
let x = result.expect(&format!("text {:?}", arg));
let x = unwrap!(result, "text {:?}", arg); // arg must be implement `Format`If used, the format string must follow the defmt syntax (documented in the manual)