cmp::Ordering vs comparison symbols

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

13 points · 1 comments · view on lemmy.world

1 Comments

sugar_in_your_tea@sh.itjust.works · 12 pts · 2y

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.