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.
Rust tips @rust

When you define an enum, add

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

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

if foo_value == Foo::Variant {…

· Web · 3 · 1

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

@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.

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