lundi 20 juin 2016

Rust if let expression, whats the word after assignment for?

Given following examples from Rust by Example

// The `if let` construct reads: "if `let` destructures `number` into
    // `Some(i)`, evaluate the block (`{}`).
    if let Some(i) = number {
        println!("Matched {:?}!", i);
    }

    // If you need to specify a failure, use an else:
    if let Some(i) = letter {
        println!("Matched {:?}!", i);

What are number & letter for? Since the block is the only think which gets executed and the variable name inside is referring to the Some(var_name) I cannot find any sense of it? Is it used like naming an anonymous function? For readability terms and understand what the following blocks context is?

Aucun commentaire:

Enregistrer un commentaire