Description
derive_more is a Rust crate that adds derive macros for many traits the standard library does not derive for you. In Rust, when you wrap a basic type in your own struct or enum, the wrapper loses the implementations of traits such as Add, Not, From and Display, and you have to write them again. This is especially tedious for the newtype pattern, such as a struct that wraps an i32. The crate removes that boilerplate for both structs and enums. The README groups the derivable traits. Conversion traits include From, Into, FromStr, TryFrom, TryInto, IntoIterator, AsRef and AsMut. Formatting traits include Debug and a Display-like group covering Binary, Octal, LowerHex, UpperHex, LowerExp, UpperExp and Pointer. The Error trait is available for error types. Operator traits include Index, Deref, the Not-like group with Neg, the Add-like group, the Mul-like group, Sum and Product, IndexMut, DerefMut and the assign variants. Each trait must be derived separately, so deriving Mul does not also derive Div. The README suggests cargo-expand to see the code generated for your own types.…
Highlights
- Derive many standard traits for structs and enums
- Conversion, formatting, error and operator traits
- Makes the newtype pattern much less tedious
- Each trait derived separately, with a documented list
- cargo-expand suggested to inspect the generated code
Ratings & Reviews
No ratings yet
Be the first to rate Derive More.
People also visit
Utoipa
Simple, Fast, Code first and Compile time generated OpenAPI documentation
Derive More FAQ
What problem does it solve?
Wrapping a Rust type in your own struct or enum loses its trait implementations, and derive_more lets you derive them again with one line.
Which traits can I derive?
Conversion traits such as From and TryFrom, formatting traits such as Debug and Display, Error, and operator traits such as Add, Mul, Index and Deref.
Does deriving one trait derive related ones?
No. The README says you must derive each trait separately, so deriving Mul does not also derive Div.
How can I see the generated code?
The README suggests cargo-expand to show your type with all derives expanded.
What are the best Derive More alternatives?
Popular alternatives to Derive More include Utoipa, Data With Rust and Rust Playground. See all Derive More alternatives




