let ... else 语句

版本新特性 / Rust 1.65

// *** before: ***
// either a staircase to the right at every check,
// or a match for the sake of a single binding
fn parse_port(text: &str) -> u16 {
    let port = match text.parse::<u16>() {
        Ok(p) => p,
        Err(_) => return 8080,
    };
    port
}

// *** in version 1.65: ***
// the binding stays in the current scope, and the else branch must leave
fn parse_port(text: &str) -> u16 {
    let Ok(port) = text.parse::<u16>() else {
        return 8080;
    };
    port
}