Macro check

Source
macro_rules! check {
    ($condition:expr) => { ... };
}
Expand description

Macro to check a condition and return false (early) if it does not hold. This is useful for checking pre-requisite conditions in predicate-type functions. Inspired by the ensure! macro from the anyhow crate. The function must return a boolean. Example:

use charms_data::check;

fn b_is_multiple_of_a(a: u32, b: u32) -> bool {
    check!(a <= b && a != 0);    // returns false early if `a` is greater than `b` or `a` is zero
    match b % a {
        0 => true,
        _ => false,
    }
}