1 unstable release

0.1.0 Nov 15, 2023

#1902 in Rust patterns

Download history 121/week @ 2024-02-08 610/week @ 2024-02-15 454/week @ 2024-02-22 494/week @ 2024-02-29 538/week @ 2024-03-07 522/week @ 2024-03-14 462/week @ 2024-03-21 265/week @ 2024-03-28 521/week @ 2024-04-04 533/week @ 2024-04-11 496/week @ 2024-04-18

1,846 downloads per month

MIT/Apache

4KB

Checking conditions with the IsNoneOr trait

The provided is_none_or method is a mirror to the core library's is_some_and method. It returns true if the option is a None or the option is Some and the value inside of it matches a predicate.

Examples

use is_none_or::IsNoneOr;

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);

lib.rs:

Checking conditions with the IsNoneOr trait

The provided is_none_or method is a mirror to the core library's is_some_and method. It returns true if the option is a None or the option is Some and the value inside of it matches a predicate.

Examples

use is_none_or::IsNoneOr;
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);

No runtime deps