1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
use std::fmt::Debug;

pub trait UnwrapUncheckedRelease<T> {
    /// # Safety
    ///
    /// unwrap without checking the invariant
    unsafe fn unwrap_unchecked_release(self) -> T;
}

impl<T> UnwrapUncheckedRelease<T> for Option<T> {
    #[inline]
    unsafe fn unwrap_unchecked_release(self) -> T {
        if cfg!(debug_assertions) {
            self.unwrap()
        } else {
            self.unwrap_unchecked()
        }
    }
}

impl<T, E: Debug> UnwrapUncheckedRelease<T> for Result<T, E> {
    #[inline]
    unsafe fn unwrap_unchecked_release(self) -> T {
        if cfg!(debug_assertions) {
            self.unwrap()
        } else {
            self.unwrap_unchecked()
        }
    }
}