std::assert! [-]  [+] [src]

macro_rules! assert {
    ($cond:expr) => (
        if !$cond {
            panic!(concat!("assertion failed: ", stringify!($cond)))
        }
    );
    ($cond:expr, $($arg:expr),+) => (
        if !$cond {
            panic!($($arg),+)
        }
    );
}

Ensure that a boolean expression is true at runtime.

This will invoke the panic! macro if the provided expression cannot be evaluated to true at runtime.

Example

fn main() { // the panic message for these assertions is the stringified value of the // expression given. assert!(true); fn some_computation() -> bool { true } assert!(some_computation()); // assert with a custom message let x = true; assert!(x, "x wasn't true!"); let a = 3i; let b = 27i; assert!(a + b == 30, "a = {}, b = {}", a, b); }
// the panic message for these assertions is the stringified value of the
// expression given.
assert!(true);
assert!(some_computation());

// assert with a custom message
assert!(x, "x wasn't true!");
assert!(a + b == 30, "a = {}, b = {}", a, b);