Module derive_more
Derive implementations for common traits.
- Crate
::derive_more. - docs.rs
- crates.io
- GitHub
derive_more extends Rust's derive macro system to automatically implement
commonly-used traits for custom types.
When wrapping types inside custom structs or enums,
the implementations of built-in traits like Add, Display, and From are lost.
derive_more provides derives that restore these implementations with minimal boilerplate,
making the newtype pattern ergonomic.
The crate provides derives across several categories:
conversion traits (From, Into, TryFrom, IntoIterator),
formatting traits (Display and related),
operator overloading (Add, Mul, Deref),
and enum utilities that generate helper methods like is_variant().
Key features include automatic operator implementations for wrapper types,
flexible Display formatting with format strings,
and comprehensive support for both structs and enums.
Examples
Deriving arithmetic operators for a newtype:
use ;
;
let a = MyInt;
let b = MyInt;
let result = a + b;
assert_eq!;
Deriving Display with custom formatting:
use Display;
let p = Point ;
assert_eq!;
Modules
- derive Module containing derive definitions only, without their corresponding traits.
- with_trait Module containing derive definitions with their corresponding traits along.