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

Rust

5771 readers
25 users here now

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

Wormhole

[email protected]

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
[–] [email protected] 12 points 8 months ago* (last edited 8 months ago)

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.