summaryrefslogtreecommitdiffstats
path: root/vendor/always-assert/README.md
blob: 7494139a123d21ee1263e83d61623b66c2c54bdc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# always-assert

Recoverable assertions, inspired by [the use of `assert()` in SQLite](https://www.sqlite.org/assert.html).

```rust
use always_assert::never;

fn apply_transaction(&mut self, tx: Transaction) -> Result<(), TransactionAborted> {
    let delta = self.compute_delta(&tx);

    if never!(!self.check_internal_invariant(&delta)) {
        // Ok, something in this transaction messed up our internal state.
        // This really shouldn't be happening, and this signifies a bug.
        // Luckily, we can recover by just rejecting the transaction.
        return abort_transaction(tx);
    }
    self.commit(delta);
    Ok(())
}
```