Coming from other functional languages (and being a Rust newbie), I\'m a bit surprised by the motivation of Rust\'s if let
syntax. The RFC mentions that without
Because your solution creates a closure, which uses resources, whereas if let
desugars exactly to your first example, which doesn't. I also find it more readable.
Rust is all about zero-cost abstractions that make programming nicer, and if let
and while let
are good examples of those (at least IMO -- I realize it's a matter of personal preference). They're not strictly necessary, but they sure feel good to use (also see: Clojure, where they were likely lifted from).