Introducing derive_aliases - a crate that allows you to define aliases for `#[derive]`, because I wasn't satisfied with any of the existing options
⚓ Rust 📅 2025-09-15 👤 surdeus 👁️ 10Here is a little crate I've developed today because I wasn't satisfied with existing options for derive aliases
crate: derive_aliases
docs.rs: crates.io: Rust Package Registry
github: GitHub - nik-rev/derive-aliases: Very elegant #[derive] aliases for Rust 💖
Advantages it offers over the other options (alternatives are listed in README.md)
- When you hover over aliases, you get documentation for them. I.e. what it expands to
- Error messages are better, e.g. if you mispell an alias
CopyasCopyou get a suggestion: "Did you mean: Copy". it also shows a list of all available aliases - These aliases are defined in a custom, very small DSL. This DSL is in a separate file. This means you can import derive aliases from other files, and share them across multiple crates
- Arguably, syntax is more intuitive, I think
..Aliasmakes more sense thanAlias!. In another derive alias crate, you had to write#[derive(...)]to define each alias. This is not needed here - If you have 2 aliases that share some derives, the derives will be merged. It won't be a compile error! This is really useful if you have some pre-requisite traits. For example, you might alias
FastHashtozerocopy::ByteHashwhich will also deriveIntoBytesandAsBytes, which are required. You might want an aliasFastEqthat deriveszerocopy::ByteEqand those 2 pre-requisite traits. With other crates, you won't be able to do this. With my crate, you can have both of them at once and the derives will be merged! - At compile-time, I parse all the derive aliases into a
Map<Derive Alias => List of derives it expands to>. This is done once across the compilation session. I really wanted the performance of myderivemacro to be fast, because I'm using it hundreds+ times. hence I don't even pull any dependencies such asquoteorsyn. I manually parseTokenStream
1 post - 1 participant
🏷️ Rust_feed