this post was submitted on 07 Jan 2024
14 points (100.0% liked)

Rust

6005 readers
3 users here now

Welcome to the Rust community! This is a place to discuss about the Rust programming language.

Wormhole

!performance@programming.dev

Credits

  • The icon is a modified version of the official rust logo (changing the colors to a gradient and black background)

founded 1 year ago
MODERATORS
 

beginner question: What is the advantage of using cmp::Ordering::Less over "<", same for Greater and Equals?

you are viewing a single comment's thread
view the rest of the comments
[–] TehPers@beehaw.org 2 points 10 months ago* (last edited 10 months ago)

~~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).~~