derive_more
derive_more
derive_more is the Swiss-army knife of Rust derive macros, with 200M+ all-time downloads. It generates trait implementations for enums, structs, and newtypes across four categories: conversions, formatting, error handling, and operators. It is particularly valuable for the newtype pattern and enums wrapping inner types.
Conversions
From,Into,TryFrom,TryInto— automatic conversion impls between wrapper types and their inner typesFromStr— parse strings into typesIntoIterator— make types iterable
Display and formatting
Display,Binary,Octal,LowerHex,UpperHex— format types with configurable templates
Error handling
Error— generatesstd::error::Errorimplementations with automaticsourceand backtrace detection from field types and names. Supportsno_stdexcept forprovide()(which requiresBacktracefromstd). A viable alternative to thiserror when you want one derive crate for multiple traits rather than a dedicated error-handling crate. For structured context beyond basic derives, snafu or error-stack remain the better choices. See rust-error-crate-comparison.
Operators
- Arithmetic:
Add,Sub,Mul,Div,Rem - Unary:
Not,Neg - Assign:
AddAssign,SubAssign, etc. - Index:
Index,IndexMut - Deref:
Deref,DerefMut
Utility methods
Constructor— generatenew()methodsIsVariant—is_variant()methods for enumsUnwrap—unwrap_variant()methods (panics on wrong variant)TryUnwrap—try_unwrap_variant()returningResult
The IsVariant, Unwrap, and TryUnwrap derives overlap with enum-as-inner's accessor methods but are bundled into a single dependency.
When to use derive_more
Use derive_more when you need trait derivation across multiple categories — conversions, formatting, operators — from a single crate. For enum-specific ergonomics (iteration, string conversion, metadata), strum is more focused. For error types specifically, thiserror is the ecosystem standard with wider adoption. See rust-enum-crates for the full landscape.
Linked from
Sources
- Raw/Rust/Comparative Deep Research on Rust Error-Handling Crates, Including Snafu.md
- Raw/Rust/Rust crates that supercharge enums and algebraic data types.md