Macro assert_cmp::assert_op

source ·
macro_rules! assert_op {
    ($left:ident $op:tt $right:ident) => { ... };
    ($left:ident $op:tt $right:literal) => { ... };
    ($left:literal $op:tt $right:ident) => { ... };
    ($left:literal $op:tt $right:literal) => { ... };
}
Expand description

Assert that a binary expression of 2 identifiers/literals returns true.

Syntax:

assert_op!($left $op $right)
  • $left and $right are either identifiers or literals or both.
  • $op is a binary operator (e.g. >, <, >=, <=, ==, !=).

Example: An assertion that passes

assert_op!(123 < 456);

Example: An assertion that fails

assert_op!(123 > 456); // panic: 123 > 456 ⇒ 123 > 456 ⇒ false