Skip to main content


Did you know that a lot of things in #Rust directly implement the `Ord` trait?

For example `Option<T>` where T: Ord

doc.rust-lang.org/std/option/e…

So you can do:

assert_eq(max(Some(0), Some(1)), Some(1))

assert_eq(max(Some(0), None), Some(0))

assert_eq(min(Some(0), None), None)

There are a lot of other things that implement `Ord`:
doc.rust-lang.org/std/cmp/trai…

#RustLang #RustTips #RustTip

in reply to modulux

Good question! I haven't tried it.

But after your question I tried and yes, `None` is lesser than anything else (which makes sense, IMO):

play.rust-lang.org/?version=st…

in reply to Jan

Thanks for the answer! I guess I could have tried it. 😳