Rust and Cargo 1 · Code patterns

Match on a value

Handle every case of an enum or option.

match maybe_user {
    Some(user) => println!("Hello, {}", user.name),
    None => println!("No user"),
}

Official Rust and Cargo 1 documentation

More code patterns commands

All code patterns commands · Rust and Cargo 1 cheatsheet

Was this page helpful?