Pre-RFC: syntax sugar for `matches!`

Another syntax that has been suggested before is expr is pat:

if src() is Ok(0) {
    /* stuff */
}

I find this more natural to read than matches, if let or a new sigil like ~=. I think it could even be added as a context-sensitive keyword, so it doesn't require a new edition.

However, I think this would only be worth it, if it would allow bindings, e.g.

if something() is Ok(n) && n > 4 && something_else(n) is Some(val) {
    println!("{}", val);
}

Because then if let could be deprecated in favor of is, which is more powerful, more general and more readable.

6 Likes