cmp::Ordering vs comparison symbols
beginner question: What is the advantage of using cmp::Ordering::Less over "<", same for Greater and Equals?
Syndicated from the fediverse. Read and engage on the original instance.
View original on programming.devbeginner question: What is the advantage of using cmp::Ordering::Less over "<", same for Greater and Equals?
1 reply
Here's a good example.
Basically,
cmp::Ordering::Lessis 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.