1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
pub struct Unwrap<T>(pub T);

impl<T: Copy> Unwrap<Option<T>> {
    pub const fn const_eval(self) -> T {
        match self.0 {
            Some(x) => x,
            None => panic!("called `Option::unwrap()` on a `None` value"),
        }
    }
}

/// Unwraps a container, returns the content.
///
/// The input type must be one of
/// + [`Option<T>`], where `T: Copy`.
///
/// The [`Copy`] bound may be relaxed in the future.
///
#[macro_export]
macro_rules! unwrap {
    ($expr: expr) => {{
        $crate::__ctfe::Unwrap($expr).const_eval()
    }};
}