1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
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)
    }
}