-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Open
Description
- I have searched open and closed issues and pull requests for duplicates, using these search terms:
- "if let"
- ch 19-2
- age > 30
- &&
- I have checked the latest
mainbranch to see if this has already been fixed, in this file:
URL to the section(s) of the book with this problem:
Description of the problem:
In chapter 19.1, near the end of section "Conditional if let Expressions", the following is written:
We can’t combine these two conditions into
if let Ok(age) = age && age > 30. The newagewe want to compare to 30 isn’t valid until the new scope starts with the curly bracket.
This is not true at the latest stable version of Rust. The following code, tested in the playground with Rust 1.92.0, edition 2024, works as expected, comparing to the "unwrapped" age of type u8:
fn main() {
let age: Result<u8, _> = "34".parse();
if let Ok(age) = age && age > 30 {
println!("Above 30: {}", age);
} else if let Ok(age) = age {
println!("Not above 30: {}", age);
} else {
println!("Err");
}
}Suggested fix:
Update the note to reflect the actual state of affairs. Hopefully a simple, quick fix.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels