# manual-let-else

Prefer let-else over an equivalent match binding

Binding a value through a match or if-let whose other branch exits obscures the required pattern and early exit.
Instead, you SHOULD use a let-else binding to state both directly.

- Category: style
- Level: warning
- Fix: suggestion
- Scope: module

## Reported

```ds title="main.ds"
function value(result: Result<int32, string>): Result<int32, string> {
    const value = match (result) {
        Ok { value } => value
        _ => return Result.err("missing value")
    };
    return Result.ok(value);
}
```

## Accepted

```ds title="main.ds"
function value(result: Result<int32, string>): Result<int32, string> {
    const Ok { value } = result else {
        return Result.err("missing value");
    };
    return Result.ok(value);
}
```

## Prior art

- [Clippy · manual_let_else](https://rust-lang.github.io/rust-clippy/master/index.html#manual_let_else)

[language/linter/src/rules/style/manual_let_else.rs:8](https://github.com/destack-sh/destack/blob/main/language/linter/src/rules/style/manual_let_else.rs#L8)
