Macro std::cmp::lex_compare
Helper macro for implementing a lexicographic order.
The macro will short-circuit the enclosuing function if lhs
and rhs
are not equal
and continue if they are.
Example
use std::cmp::{Ordering, Comparable, lex_compare};
struct IPv4 {
a: u8,
b: u8,
c: u8,
d: u8,
}
impl IPv4 {
fn compare(lhs: &IPv4, rhs: &IPv4) -> Ordering {
lex_compare!(lhs.a, rhs.a);
lex_compare!(lhs.b, rhs.b);
lex_compare!(lhs.c, rhs.c);
lex_compare!(lhs.d, rhs.d);
Ordering::Equal
}
mixin Comparable<IPv4>;
}
Run this example