tuwunel_core/utils/result/unwrap_infallible.rs
1use std::convert::Infallible;
2
3use super::{DebugInspect, Result};
4use crate::error;
5
6pub trait UnwrapInfallible<T> {
7 fn unwrap_infallible(self) -> T;
8}
9
10impl<T> UnwrapInfallible<T> for Result<T, Infallible> {
11 #[inline]
12 fn unwrap_infallible(self) -> T {
13 // SAFETY: Branchless unwrap for errors that can never happen. In debug
14 // mode this is asserted.
15 unsafe {
16 self.debug_inspect_err(error::infallible)
17 .unwrap_unchecked()
18 }
19 }
20}