derive_aliases 0.2.1

`#[derive]` aliases for reducing code boilerplate
Documentation

#[derive] aliases for reducing code boilerplate

Aliases are defined in a special file derive_aliases.rs, located next to your crate's Cargo.toml:

// Simple derive aliases
//
// `#[derive(..Copy, ..Eq)]` expands to `#[std::derive(Copy, Clone, PartialEq, Eq)]`

Copy = Copy, Clone;
Eq = PartialEq, Eq;

// You can nest them!
//
// `#[derive(..Ord, std::hash::Hash)]` expands to `#[std::derive(PartialOrd, Ord, PartialEq, Eq, std::hash::Hash)]`

Ord = PartialOrd, Ord, ..Eq;

This file uses a tiny domain-specific language for defining the derive aliases (the parser is less than 20 lines of code!). .rs is used just for syntax highlighting. These aliases can then be used in Rust like so:

// This globally overrides `std::derive` with `derive_aliases::derive` across the whole crate! Handy.
#[macro_use]
extern crate derive_aliases;

#[derive(..Copy, ..Ord, std::hash::Hash)]
struct HelloWorld;

This expands to:

#[derive(Copy, Clone, PartialOrd, Ord, PartialEq, Eq, std::hash::Hash)]
struct HelloWorld;

Single derive_aliases.rs in Cargo Workspaces

If you want to use the same derive_aliases.rs for all crates in your Cargo workspace, enable the workspace feature then define the CARGO_WORKSPACE_DIR env variable in .cargo/config.toml:

[env]
CARGO_WORKSPACE_DIR = { value = "", relative = true }

Documentation on hover

With Ord alias defines as follows:

Eq = PartialEq, Eq;
Ord = PartialOrd, Ord, ..Eq;

Hovering over ..Ord will show that it expands to PartialOrd, Ord, PartialEq, Eq:

hovering shows docs

use other alias files in derive_aliases.rs

use followed by a path will inline the derive aliases located in that file.

If ../my_other_aliases.rs contains:

Ord = PartialOrd, Ord, ..Eq;

And your derive_aliases.rs has:

use "../my_other_aliases.rs";

Eq = PartialEq, Eq;

Then it will inline the aliases in the other file, expanding to:

Ord = PartialOrd, Ord, ..Eq;
Eq = PartialEq, Eq;