Rust tips is a user on octodon.social. You can follow them or interact with them if you have an account anywhere in the fediverse. If you don't, you can sign up here.

When you define an enum, add

#[derive(PartialEq, Eq)]
enum Foo {…}

to make it work with `==`, e.g.

if foo_value == Foo::Variant {…

@rust why both PartialEq and Eq? I haven't quite grasped it yet

Rust tips @rust

@wzhd Floating-point NaN is weird in that NaN != NaN. Rust has PartialEq too express this. Eq is the usual ==, but it inherits from PartialEq, so you need both.

· Web · 0 · 0

@rust oh right, when a trait inherits another trait, both have to be implemented (or derived). Thank you so much for tips!