luminasapphira,

I’m guessing you’re asking because you got a clippy lint. Using Ordering allows you to match the output therefore only calling partial_ord once, compared to using an if-else chain which might call it several times. In many/most cases this would probably be compiler optimized anyway but this makes it explicit.

TehPers, (edited )

What language? (I’m an idiot) If you’re referring to Rust, std::cmp::Ordering is an enum and can be used withPartialOrd/Ord to see how two values compare. The comparison operators basically call your partial_ord implementation. If you can use the operators themselves, use them instead of calling partial_ord in most cases.

In other languages, I don’t know, but I assume in general if you can use the operators, you should (unless you’re interested specifically in their ordering, not whether one is only one of greater than, equal to, or less than another).

sugar_in_your_tea,

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.

  • All
  • Subscribed
  • Moderated
  • Favorites
  • rust@programming.dev
  • DreamBathrooms
  • everett
  • osvaldo12
  • magazineikmin
  • thenastyranch
  • rosin
  • normalnudes
  • Youngstown
  • Durango
  • slotface
  • ngwrru68w68
  • kavyap
  • mdbf
  • InstantRegret
  • JUstTest
  • ethstaker
  • GTA5RPClips
  • tacticalgear
  • Leos
  • anitta
  • modclub
  • khanakhh
  • cubers
  • cisconetworking
  • megavids
  • provamag3
  • tester
  • lostlight
  • All magazines