I was reading the Rust Programming Language Book, and I have stumbled at the part about if let.
The example in the book is the following:
let some_u8_value = Some(0u8);
match some_u8_value {
Some(3) => println!("three"),
_ => (),
}
This is apparently equivalent to:
if let some(3) = some_u8_value {
println!("three");
}
I was not sure why this if let was needed, why not just:
if some_u8_value == Some(3) {
println!("three");
}
So I was looking into match statements, and I found the following example:
let some_u8_value = Some(3u8);
match some_u8_value {
Some(i) => println!("Matched: {}",i),
None => ()
}
Which is apparently equivalent to:
let some_u8_value = Some(3u8);
if let Some(i) = some_u8_value {
println!("assigned {} to i",i);
}
Where does the "i" come from? It seems to be a "catch all for u8 values. I am under the impression that understanding the use of i here is the key to understanding the examples in the Rust Programming Language Book.
Thankyou for any help