always-assert

Crates.ioalways-assert
lib.rsalways-assert
version0.2.0
sourcesrc
created_at2021-01-26 17:51:33.454843
updated_at2024-01-23 11:35:29.272431
descriptionRecoverable assertions for long-running robust applications
homepage
repositoryhttps://github.com/matklad/always-assert
max_upload_size
id346948
size19,642
owners (github:badrobotics:owners)

documentation

README

always-assert

Recoverable assertions, inspired by the use of assert() in SQLite.

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(())
}
Commit count: 7

cargo fmt