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

Rust

5938 readers
4 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?

top 1 comments
sorted by: hot top controversial new old
[–] [email protected] 12 points 10 months ago* (last edited 10 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.