Macro dbc::ensure [] [src]

macro_rules! ensure {
    ($cond:expr) => { ... };
    ($cond:expr, $($args:tt)*) => { ... };
}

Postcondition tests

This macro is used to assert postconditions. Any variables passed will stringify both the variable and their values. Structs can be displayed only if they have the [#derive(Debug)] attribute.

Examples


fn foo(x: i32, y: i32) -> i32 {
    require!(x != 0, x, y);
    require!(y < 0, x, y);

    let sum = x + y;

    // Ensure passes
    ensure!(sum == x + y, sum, x, y);

    // Ensure fails
    ensure!(sum != x + y, sum, x, y);

    sum
}

fn main() {
    // No asserts
    let a = foo(10, -100);
}