macro_rules! vortex_ensure_eq {
($left:expr, $right:expr $(,)?) => { ... };
($left:expr, $right:expr, $fmt:literal $(, $arg:expr)* $(,)?) => { ... };
}Expand description
A macro that mirrors assert_eq! but instead of panicking when left != right, it will
immediately return an erroneous VortexResult to the calling context.
Both values must implement PartialEq and Display, and each is
evaluated exactly once. Use vortex_ensure! for values that do not implement Display.
By default the error shows both expressions and their values, so most callers do not need a message:
fn check(len: usize) -> VortexResult<()> {
vortex_ensure_eq!(len, 2);
Ok(())
}
let err = check(3).unwrap_err().to_string();
assert!(err.starts_with("`len == 2`\n left: 3\n right: 2"));A message replaces the expressions. The values are still appended, so the message does not need to repeat them:
fn check(len: usize) -> VortexResult<()> {
vortex_ensure_eq!(len, 2, "map entries must have {} fields", 2);
Ok(())
}
let err = check(3).unwrap_err().to_string();
assert!(err.starts_with("map entries must have 2 fields\n left: 3\n right: 2"));