alertsleeper@programming.dev to Rust@programming.dev · 1 year agocmp::Ordering vs comparison symbolsmessage-squaremessage-square1fedilinkarrow-up113arrow-down10file-text
arrow-up113arrow-down1message-squarecmp::Ordering vs comparison symbolsalertsleeper@programming.dev to Rust@programming.dev · 1 year agomessage-square1fedilinkfile-text
beginner question: What is the advantage of using cmp::Ordering::Less over “<”, same for Greater and Equals?
minus-squaresugar_in_your_tealinkfedilinkarrow-up12·edit-21 year agoHere’s a good example. Basically, cmp::Ordering::Less is an enum so a match using it is guaranteed to be exhaustive, whereas you need to be careful when doing an if/else chain that you cover all cases.
Here’s a good example.
Basically,
cmp::Ordering::Less
is an enum so a match using it is guaranteed to be exhaustive, whereas you need to be careful when doing an if/else chain that you cover all cases.