mod sealed {
pub trait Sealed {}
}
pub trait OptionExt: Sized + sealed::Sealed {
type T;
fn is_none_or(self, f: impl FnOnce(Self::T) -> bool) -> bool;
fn contains<U>(&self, u: &U) -> bool
where
Self::T: PartialEq<U>;
}
impl<T> sealed::Sealed for Option<T> {}
impl<T> OptionExt for Option<T> {
type T = T;
#[inline]
fn is_none_or(self, f: impl FnOnce(Self::T) -> bool) -> bool {
match self {
Some(value) => f(value),
None => true,
}
}
#[inline]
fn contains<U>(&self, u: &U) -> bool
where
Self::T: PartialEq<U>,
{
self.as_ref().is_some_and(|this| *this == *u)
}
}