[rust-dev] Rationale on if let

Paul Colomiets paul at colomiets.name
Mon Oct 13 02:00:13 PDT 2014


Hi Michael,

On Mon, Oct 13, 2014 at 8:41 AM, Michael Giagnocavo <mgg at giagnocavo.net> wrote:
> I came across the "if let" syntax, and it's been bothering me a bit.
>
> It seems like a strange thing to elevate to a grammar-level construct.
>
> The example given is:
> if let Some(x) = foo() {
>     doSomethingWith(x)
> }
>
> What's wrong with e.g.:
>
> foo().if_some!(|x| { doSomethingWith(x) })?

At least you cant "break" or "return" (from outer function). Also
borrow rules sometimes are more complex when using closure.

--
Paul


More information about the Rust-dev mailing list