OptionExt

Trait OptionExt 

Source
pub trait OptionExt<T> {
    // Required method
    fn is_none_or(self, f: impl FnOnce(T) -> bool) -> bool;
}
Expand description

Extensions for Option<T>.

See also ACP #212

Required Methods§

Source

fn is_none_or(self, f: impl FnOnce(T) -> bool) -> bool

Returns true if the option is a None or the value inside of it matches a predicate.


let x: Option<u32> = Some(2);
assert_eq!(x.is_none_or(|x| x > 1), true);

let x: Option<u32> = Some(0);
assert_eq!(x.is_none_or(|x| x > 1), false);

let x: Option<u32> = None;
assert_eq!(x.is_none_or(|x| x > 1), true);

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl<T> OptionExt<T> for Option<T>

Source§

fn is_none_or(self, f: impl FnOnce(T) -> bool) -> bool

Implementors§