macro_rules! unwrap_err {
    ($res:expr) => { ... };
}
Expand description

Gets the value in the Err variant.

Panics

This panics if $res is an Ok, including the debug-formatted value in the panic message.

Example

use const_panic::unwrap_err;

type Res = Result<u32, &'static str>;

const ERR: &str = unwrap_err!(Res::Err("this is an error"));

assert_eq!(ERR, "this is an error");

Error

This is what the compile-time error looks like when attempting to unwrap an Ok:

error[E0080]: evaluation of constant value failed
 --> src/macros/unwrapping.rs:174:19
  |
8 | const ERR: &str = unwrap_err!(Res::Ok(1234));
  |                   ^^^^^^^^^^^^^^^^^^^^^^^^^^ the evaluated program panicked at '
invoked `unwrap_err` macro with an `Ok` value: 1234', src/macros/unwrapping.rs:8:19
  |