derive_aliases

Crates.ioderive_aliases
lib.rsderive_aliases
version0.2.2
created_at2025-09-15 00:27:57.295848+00
updated_at2025-09-15 05:07:59.76512+00
description`#[derive]` aliases for reducing code boilerplate
homepage
repositoryhttps://github.com/nik-rev/derive-aliases
max_upload_size
id1839290
size36,699
Nik Revenco (nik-rev)

documentation

README

derive_aliases

crates.io github docs.rs

This crate provides #[derive] aliases for reducing code boilerplate.

Features

  • Intuitive, simple syntax
    • Create alias: Copy = Copy, Clone
    • Use alias: #[derive(Debug, ..Copy)] expands to #[std::derive(Debug, Copy, Clone)]
  • Very fast compile times, we don't pull any dependencies as our parsing logic is very simple
  • Hovering on the aliases shows you documentation on what they expand into

Usage

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;

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

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 }

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;

Minimum Supported Rust Version (MSRV)

1.80

Alternatives

Commit count: 48

cargo fmt