@@ -15,14 +15,14 @@ impl Ticket {
|
||||
}
|
||||
```
|
||||
|
||||
You only care about the `Status::InProgress` variant.
|
||||
You only care about the `Status::InProgress` variant.
|
||||
Do you really need to match on all the other variants?
|
||||
|
||||
New constructs to the rescue!
|
||||
|
||||
## `if let`
|
||||
|
||||
The `if let` construct allows you to match on a single variant of an enum,
|
||||
The `if let` construct allows you to match on a single variant of an enum,
|
||||
without having to handle all the other variants.
|
||||
|
||||
Here's how you can use `if let` to simplify the `assigned_to` method:
|
||||
@@ -61,8 +61,8 @@ as the code that precedes it.
|
||||
|
||||
## Style
|
||||
|
||||
Both `if let` and `let/else` are idiomatic Rust constructs.
|
||||
Use them as you see fit to improve the readability of your code,
|
||||
Both `if let` and `let/else` are idiomatic Rust constructs.\
|
||||
Use them as you see fit to improve the readability of your code,
|
||||
but don't overdo it: `match` is always there when you need it.
|
||||
|
||||
## References
|
||||
|
||||
Reference in New Issue
Block a user