|
|
|
|
|
by ai_
222 days ago
|
|
if let makes a lot more sense when you learn that a normal let expression also takes a pattern[1]. let Coordinates(x, y) = get_coords();
But this is intended for "exhaustive patterns". If you can't express an exhaustive pattern, like with an Option, then you can use let ... else let Some((x, y)) = get_coords() else { return };
if let is just an extension of this "let pattern" system.Once you internalize how patterns work (and they really work everywhere) it all starts to really make sense and feels a lot cleaner. [1]: https://doc.rust-lang.org/reference/patterns.html |
|