you are viewing a single comment's thread
view the rest of the comments
[–] 1 point 1 year ago (4 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.

  • source
  • parent
  • hideshow 4 child comments
  • [–] 1 point 1 year ago (3 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!();
    };
    
  • source
  • parent
  • hideshow 3 child comments
  • [–] 1 point 1 year ago* (last edited 1 year ago) (2 children)
  • [–] 1 point 1 year ago (1 child)

    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.

  • source
  • parent
  • hideshow 1 child comment
  • [–] 1 point 1 year ago* (last edited 1 year 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.

  • source
  • parent