How to avoid sticking the same #[derive]s everywhere?

81 points Merlindru 64 comments

I find that a lot of structs and enums I create in my project (which consists of multiple crates) I just end up copy pasting this nonsense:

#[derive(Debug, Clone, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[cfg_attr(feature = "specta", derive(specta::Type))]

I'd rather have all my structs and enum have a set of derives by default, and then take them away as needed.

I know people will argue this goes against the "no implicit stuff" rule of Rust, but is there any practical way to make this happen? Any crate?

TIA! :)