Skip to main content

tuwunel_core/utils/result/
is_err_or.rs

1#![expect(clippy::wrong_self_convention)]
2
3use super::Result;
4
5/// Tests whether a result is an error or its success value matches a predicate.
6///
7/// Every `Err` result returns true without exposing the error. An `Ok` result
8/// is consumed and passed to the predicate.
9pub trait IsErrOr<T> {
10	/// Returns true for any error or a matching success value.
11	///
12	/// The predicate is called only for the `Ok` branch. Both the success value
13	/// and any error are consumed.
14	fn is_err_or<F: FnOnce(T) -> bool>(self, f: F) -> bool;
15}
16
17impl<T, E> IsErrOr<T> for Result<T, E> {
18	#[inline]
19	fn is_err_or<F>(self, f: F) -> bool
20	where
21		F: FnOnce(T) -> bool,
22	{
23		self.map_or(true, f)
24	}
25}