jiff/util/
constant.rs

1/// Unwrap an `Option<T>` in a `const` context.
2///
3/// If it fails, panics with the given message.
4macro_rules! unwrap {
5    ($val:expr, $msg:expr$(,)?) => {
6        match $val {
7            Some(val) => val,
8            None => panic!($msg),
9        }
10    };
11}
12
13/// Unwrap a `Result<T, E>` in a `const` context.
14///
15/// If it fails, panics with the given message.
16macro_rules! unwrapr {
17    ($val:expr, $msg:expr$(,)?) => {
18        match $val {
19            Ok(val) => val,
20            Err(_) => panic!($msg),
21        }
22    };
23}
24
25pub(crate) use {unwrap, unwrapr};