Why “continue” in a match match does not need to check the type?

The rust guessing tutorial has the following code example:

let guess: u32 = match guess.trim().parse() {
    Ok(num) => num,
    Err(_) => continue,
};

The result of the match should be u32, and this happens in the branch Ok(num). However, the branch Err(_)returns continue, which is certainly not u32. Why does this typecheck and work?

+4
source share
1 answer

However, the branch Err(_)returnscontinue

Not really. continue- this is not what "returns", it is what changes the flow of code. Since this hand match does not give a value, the type of it does not matter. matchgenerally does typecheck - each resulting value is equal u32.

, return break.

. , , .

panic!("...") unimplemented!() , .

+8

Source: https://habr.com/ru/post/1672881/


All Articles