#[cfg(not(debug_assertions))]
use core::hint::unreachable_unchecked;
pub trait UnwrapUnchecked {
type Output;
unsafe fn unwrap_unchecked(self) -> Self::Output;
}
impl<T> UnwrapUnchecked for Option<T> {
type Output = T;
#[inline]
#[track_caller]
#[cfg(debug_assertions)]
unsafe fn unwrap_unchecked(self) -> Self::Output {
self.unwrap()
}
#[inline]
#[cfg(not(debug_assertions))]
unsafe fn unwrap_unchecked(self) -> Self::Output {
self.unwrap_or_else(|| unsafe { unreachable_unchecked() })
}
}
impl<T, E: core::fmt::Debug> UnwrapUnchecked for Result<T, E> {
type Output = T;
#[inline]
#[track_caller]
#[cfg(debug_assertions)]
unsafe fn unwrap_unchecked(self) -> Self::Output {
self.unwrap()
}
#[inline]
#[cfg(not(debug_assertions))]
unsafe fn unwrap_unchecked(self) -> Self::Output {
self.unwrap_or_else(|_| unsafe { unreachable_unchecked() })
}
}