logo
Expand description

Introduce if let PAT = EXPR { BODY } construct.

if let Some(x) = opt_val {
    do(x);
} else if cond() {
    do();
} else {
    do();
}

desugar:

match opt_val {
    Some(x) => {
        do(x);
    }
    _ if cond() => {}
    _ => {}
}

Note

  • else if => _ if guard => {}
  • else => _ => {}

RFC: 0160-if-let