4 ms·
As someone who doesn't write Rust professionally, this list scares me a bit. Even though many items apply to other programming languages as well (and some are
by davidkunz 5y ago
As someone who doesn't write Rust professionally, this list scares me a bit. Even though many items apply to other programming languages as well (and some are even handled more easily in Rust), it appears to be quite easy to forget something of great importance to some of your users. What if you forgot to derive the Debug/Display trait and someone wants to print your struct, or you forgot to implement PartialEq and someone wants to write unit tests? Maybe this doesn't really happen in practice, I would be very interested if some experienced Rustaceans could share their experience.
- deleted 5y ago[deleted]
- loa_in_ 5y agoThis does happen in practice. Usually it is remedied by submitting an issue or a PR to your dependency upstream and getting them to fix it. If you're really impatient you can implement the trait yourself (with some hacking involved): wrap the type in a new struct and implement the trait there. Why hacking around like that? Rust requires at least one of: the type, or the trait; to be originated in your crate.
- duped 5y agoNot everything is printable, comparable, or equalable (#[derive(Debug PartialEq)] isn't guaranteed to work - it has a few preconditions). So you live with it. If you draw a comparison to C++, almost none of these things are implemented for dependencies and there's no easy helper to add it.
- AaronFriel 5y agoIn cases like this, since everything is on GitHub it turns out to be pretty easy to make a PR to fix - it's usually only a few characters of code change. API names and such are of course breaking changes, but unless you're authoring Tokio or Hyper or another huge, important crate in the ecosystem, it's really not worth it to do everything on this list.
- davidkunz 5y agoI just found an interesting reddit thread discussing must-have traits: https://teddit.net/r/rust/comments/p5vsjl/is_there_any_reason_not_to_derive_every_possible/ https://teddit.net/r/rust/comments/p5vsjl/is_there_any_reaso...