-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Description
Hey guys!
First of all - thank you very much for the great language and the great book. I'm new to coding, so I'm sorry if anything (or everything) I say is stupid.
At least for me, there is a very bad example in the "6.3 Concise Control Flow with if let" chapter. It says:
if let Some(3) = some_u8_value {
println!("three");
}
I had been somewhat at a loss as to why or how this expression is any better than say
if Some(3) == some_u8_value {
println!("three");
}
and it took me some time to come to the conclusion that in this particular case it probably isn't better at all, if not worse for arguably "weird" (for me in that state of mind) syntax. By weird, I mean that at the time the part after "if" looked like
let 3 = x
for me, which had just turned my head around :)
Long story short, I think it is more clear to explain "if let" through use of unwrapping the optional value (if it is there), like so:
if let Some(x) = some_u8_value {
println!("The unwrapped value is {}", x);
}
I hope that makes sense.