std-method

Option::is_some_and / is_none_or

Validate an optional limit. The first requires a present passing value; the second accepts absence or a passing value. Both consume self. Expected stdout (not executed): true true Common mistake: Treating absence as false for both methods.

Formal Syntax & Structure

rust syntaxrust
fn is_some_and(self, f: impl FnOnce(T) -> bool) -> bool; fn is_none_or(self, f: impl FnOnce(T) -> bool) -> bool

Working Example

Example Snippetrust
fn main() {    let limit = Some(8);    println!("{} {}", limit.is_some_and(|n| n > 0), None::<i32>.is_none_or(|n| n > 0));}
Rust Reference