Macro gazebo::cmp_chain [−][src]
macro_rules! cmp_chain {
($e : expr) => { ... };
($e : expr, $($x : expr), + $(,) ?) => { ... };
}
Expand description
Performs a chain of comparison operation expressions yielding std::cmp::Ordering
, supporting
early exit upon hitting the first expressions that doesn’t yield std::cmp::Ordering::Equal
and returning the result of that. This is useful for easily writing a sequence of expressions
necessary to yield a comparison result.
The macro is expanded inplace, so any expressions dealing with Result
types are allowed
provided that the larger scope allows returning result.
use std::cmp::Ordering;
use gazebo::cmp_chain;
assert_eq!(
cmp_chain! {
1.cmp(&1),
Ok::<_, ()>(2.cmp(&2))?,
3.cmp(&4),
panic!("won't reach this"),
},
Ordering::Less,
);