std-method

Result::is_ok and is_err

Test the variant by borrowing the Result. This reports success or failure but leaves the payload intact for later handling. Expected stdout (not executed): false true Common mistake: Treating is_ok as the successful payload itself.

Formal Syntax & Structure

rust syntaxrust
fn is_ok(&self) -> bool; fn is_err(&self) -> bool

Working Example

Example Snippetrust
fn main() {    let value = "no".parse::<u32>();    println!("{} {}", value.is_ok(), value.is_err());}
Rust Reference