derive_aliases
This crate improves Rust's derive macro by supporting user-defined Derive aliases.
[]
= "0.4"
Usage
Define aliases using define!, and use them with #[derive]:
use derive;
// Use the aliases:
;
The above expands to this:
;
#[derive(..Eq)]- expands to
#[derive(::core::cmp::PartialEq, ::core::cmp::Eq)]
- expands to
#[derive(..Ord)]- expands to
#[derive(..Eq, ::core::cmp::PartialOrd, ::core::cmp::Ord)] - ...which expands to
#[derive(::core::cmp::PartialEq, ::core::cmp::Eq, ::core::cmp::PartialOrd, ::core::cmp::Ord)]
- expands to
How it works:
derive_aliases::define!expands to a bunch ofmacro_rules!items. Each macro item is the real alias#[derive_aliases::derive]expands to a bunch of calls to macros atcrate::derive_alias
IDE Support
Hovering over an alias #[derive(..Alias)] shows exactly what it expands into, and even Goto Definition directly brings you where the alias is defined.

Tip
To globally override #[std::derive] with #[derive_aliases::derive], add the following:
extern crate derive_aliases;
The above lets you define! aliases and then use them anywhere in your crate!
I have put a ton of effort into optimizing derive_aliases to be as zero-cost as possible in terms of compile-time over the standard library's derive,
so don't worry about any overhead of #[derive_aliases::derive] even when no aliases are used! derive_aliases has 0 dependencies (not even quote or syn!)
Derives are de-duplicated
Each derive alias expands into a bunch of derives, then de-duplicated. If there are 2 or more of the same derive, only 1 is kept. This is useful when there are some "pre-requisite" derives needed, but if they already exist then don't add them (instead of compile error'ing).
extern crate zerocopy;
;
// expands to:
;
;
// expands to:
;
;
// expands to:
;
// note that the 2 `Immutable` and 2 `IntoBytes` derives were de-duplicated
Splitting up derive aliases
All derive aliases must exist at your crate::derive_alias, so invoke the derive_aliases::define! macro there.
You can break define! apart into multiple definitions:
;
The above Just Works. Most importantly, derive aliases need to available at crate::derive_alias.
Sharing derives across multiple crates
Use #![export_derive_aliases] inside of a call to derive_aliases::define! to allow aliases to be used in other crates:
// crate `foo`:
In another crate, import the aliases:
// crate which contains `Eq` and `Ord` aliases
extern crate foo;
use derive;
;
For details, hover over #![export_derive_aliases] in your editor