std-method
Result::is_ok_and / is_err_and
Check a condition on only the selected variant. These methods consume the Result; borrow with as_ref first if it must remain available. Expected stdout (not executed): true Common mistake: Expecting is_ok_and to run its predicate for Err.
Formal Syntax & Structure
rust syntaxrust
fn is_ok_and(self, f: impl FnOnce(T) -> bool) -> bool; fn is_err_and(self, f: impl FnOnce(E) -> bool) -> boolWorking Example
Example Snippetrust
fn main() { let result: Result<i32, &str> = Ok(9); println!("{}", result.is_ok_and(|n| n >= 5));}