chain_cmp
Use the chmp!
macro to chain comparison operators like you can in Python, for example.
You can use all of these operators <
, <=
, >
, >=
, ==
, !=
inside a chmp!
invocation.
Examples
Basic usage
use chmp;
let = ;
let verbose = a < b && b <= c;
let concise = chmp!;
assert_eq!;
// You can use equality operators as well:
assert!;
// And you can even chain more than three operators:
assert!; // making sure these values are pairwise distinct
// And of course mix and match operators:
assert!;
Short-circuiting
chmp!
will short-circuit to evaluate the fewest expressions
possible.
assert!; // this **won't** panic
Comparing arbitrary expressions
As long as the comparison operators have the lowest precedence,
chmp!
will evaluate any expression, like variables, blocks,
function calls, etc.
const ANSWER: u32 = 42;
assert!;