Skip to main content

tuwunel_core/utils/result/
unwrap_or_err.rs

1use std::convert::identity;
2
3use super::Result;
4
5/// Returns the Ok value or the Err value. Available when the Ok and Err types
6/// are the same. This is a way to default the result using the specific Err
7/// value rather than unwrap_or_default() using Ok's default.
8pub trait UnwrapOrErr<T> {
9	fn unwrap_or_err(self) -> T;
10}
11
12impl<T> UnwrapOrErr<T> for Result<T, T> {
13	#[inline]
14	fn unwrap_or_err(self) -> T { self.unwrap_or_else(identity::<T>) }
15}