std-type

Ordering — comparison outcomes

Ordering expresses the direction of a comparison. then_with uses a second comparison only if the first is Equal, which is useful for tie-breaking. Expected stdout (not executed): Greater Common mistake: Treating Ordering as a Boolean comparison result.

Formal Syntax & Structure

rust syntaxrust
enum Ordering { Less, Equal, Greater }

Working Example

Example Snippetrust
fn main() {    let a = (2u8, 8u8);    let b = (2u8, 3u8);    let order = a.0.cmp(&b.0).then_with(|| a.1.cmp(&b.1));    println!("{order:?}");}
Rust Reference