const_str/__ctfe/
unwrap.rs

1pub struct Unwrap<T>(pub T);
2
3impl<T: Copy> Unwrap<Option<T>> {
4    pub const fn const_eval(self) -> T {
5        match self.0 {
6            Some(x) => x,
7            None => panic!("called `Option::unwrap()` on a `None` value"),
8        }
9    }
10}
11
12/// Unwraps a container, returns the content.
13///
14/// The input type must be one of
15/// + [`Option<T>`], where `T: Copy`.
16///
17/// The [`Copy`] bound may be relaxed in the future.
18///
19/// This macro is [const-fn compatible](./index.html#const-fn-compatible).
20#[macro_export]
21macro_rules! unwrap {
22    ($expr: expr) => {{
23        $crate::__ctfe::Unwrap($expr).const_eval()
24    }};
25}