std::macros::assert
macro_rules! assert( ($cond:expr) => ( if !$cond { fail!("assertion failed: {:s}", stringify!($cond)) } ); ($cond:expr, $msg:expr) => ( if !$cond { fail!($msg) } ); ($cond:expr, $($arg:expr),+) => ( if !$cond { fail!($($arg),+) } ); )
Ensure that a boolean expression is true
at runtime.
This will invoke the fail!
macro if the provided expression cannot be
evaluated to true
at runtime.
Example
// the failure 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);