this post was submitted on 01 Sep 2025
31 points (94.3% liked)

Rust

7312 readers
127 users here now

Welcome to the Rust community! This is a place to discuss about the Rust programming language.

Wormhole

!performance@programming.dev

Credits

  • The icon is a modified version of the official rust logo (changing the colors to a gradient and black background)

founded 2 years ago
MODERATORS
you are viewing a single comment's thread
view the rest of the comments
[–] smiletolerantly@awful.systems 0 points 2 days ago (1 children)

Drop if-let

Over my cold dead body. if-let-else is such a fantastic pattern. Makes everything an order of magnitude more readable. Works so nicely for unwrapping opts/errs.

[–] TehPers@beehaw.org 1 points 2 days ago (1 children)

Their suggested replacement is closer to C#'s is keyword:

if foo is Some(foo) {
    // ...
}

The issue here is that we still have let-else, which can't be translated as easily:

let Some(foo) = foo else {
    todo!();
};
[–] soc@programming.dev 1 points 2 days ago* (last edited 2 days ago) (1 children)
[–] TehPers@beehaw.org 1 points 2 days ago (1 children)

That's not an alternative, it's removing let-else entirely. It's equivalent to this:

let i = if let Some(i) = opt_number {
    i
} else {
    return 0;
};

let-else is specifically a feature that allows you to use a refutable pattern to deconstruct a value by providing a diverging else branch.

[–] soc@programming.dev 1 points 2 days ago* (last edited 2 days ago)

Removing let-else is the whole point of the linked article series:

Being able to do to everything Rust does, but without Rust's zoo of if-then-else, match, if-let, let-else etc.