alertsleeper@programming.dev to Rust@programming.dev · 10 months agocmp::Ordering vs comparison symbolsmessage-squaremessage-square3fedilinkarrow-up113arrow-down10file-text
arrow-up113arrow-down1message-squarecmp::Ordering vs comparison symbolsalertsleeper@programming.dev to Rust@programming.dev · 10 months agomessage-square3fedilinkfile-text
beginner question: What is the advantage of using cmp::Ordering::Less over “<”, same for Greater and Equals?
minus-squaresugar_in_your_tea@sh.itjust.workslinkfedilinkarrow-up12·edit-210 months 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.