Derivable traits: the derive attribute for Debug, Clone, and Copy
Answer: The #[derive] attribute asks the compiler to provide a basic implementation of some traits. Debug, Clone, and Copy are among the traits you can use with derive. Display cannot be derived, because it has no sensible default behavior.
What derive generates
The book's derive attribute can sit on a struct or enum definition.
That attribute generates the code for a default trait implementation on the annotated type.
Appendix C lists the standard-library traits you can use with derive.
Other traits in the standard library don't have sensible default behavior. Implement them in the way that makes sense.
Display, which handles formatting for end users, is an example of a trait that can't be derived.
Libraries may add derive for their own traits, so the list is not comprehensive.
Debug formatting in format strings uses :? inside {} placeholders. assert_eq! requires Debug.
Traits the compiler can fill in
Via the #[derive] attribute, the compiler can provide basic implementations for some traits.
A manual implementation remains available when more complex behavior is required.
Comparison traits that can be derived are Eq, PartialEq, Ord, and PartialOrd.
Clone is used to create T from &T via a copy.
Copy gives a type copy semantics instead of move semantics.
See also
Claims
- id: C1 claim: You can apply derive to a struct or enum definition. source: S1 evidence: "apply to a struct or enum definition"
- id: C2 claim: Display is an example of a trait that can't be derived. source: S1 evidence: "a trait that can't be derived is Display"
- id: C3 claim: The compiler can provide basic implementations via the #[derive] attribute. source: S2 evidence: "via the #[derive] attribute"
- id: C4 claim: Derivable comparison traits include Eq, PartialEq, Ord, and PartialOrd. source: S2 evidence: "Eq , PartialEq , Ord , PartialOrd"
- id: C5 claim: Clone creates T from &T via a copy. source: S2 evidence: "to create T from &T via a copy"
Sources
- [S1] Appendix C: Derivable Traits. The Rust Programming Language. https://doc.rust-lang.org/book/appendix-03-derivable-traits.html . License: MIT OR Apache-2.0. Accessed 2026-11-23.
- [S2] Derive. Rust by Example. https://doc.rust-lang.org/rust-by-example/trait/derive.html . License: MIT OR Apache-2.0. Accessed 2026-11-23.
License: this note is CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Summary by iinventedlight (AI-assisted). Sources: The Rust Programming Language, Appendix C: Derivable Traits; Rust by Example, Derive. MIT OR Apache-2.0 (https://raw.githubusercontent.com/rust-lang/book/main/LICENSE-MIT). Copyright the Rust Project Developers. MIT OR Apache-2.0 (https://raw.githubusercontent.com/rust-lang/rust-by-example/master/LICENSE-MIT). Copyright the Rust Project Developers. Text was condensed and changed from the originals.
License: CC-BY-4.0 · Summary by iinventedlight (AI-assisted). Sources: The Rust Programming Language, Appendix C: Derivable Traits; Rust by Example, Derive. MIT OR Apache-2.0 (https://raw.githubusercontent.com/rust-lang/book/main/LICENSE-MIT). Copyright the Rust Project Developers. MIT OR Apache-2.0 (https://raw.githubusercontent.com/rust-lang/rust-by-example/master/LICENSE-MIT). Copyright the Rust Project Developers.
Cite this
iinventedlight. 2026. "Derivable traits: the derive attribute for Debug, Clone, and Copy." iinventedlight Library, iil:note:56f7rxfx, version of 2026-11-23. https://iinventedlight.com/library/notes/rust-derivable-traits/. License: CC-BY-4.0.
@misc{iil_note_56f7rxfx,
author = {{iinventedlight}},
title = {{Derivable traits: the derive attribute for Debug, Clone, and Copy}},
howpublished = {iinventedlight Library},
year = {2026},
date = {2026-11-23},
url = {https://iinventedlight.com/library/notes/rust-derivable-traits/},
note = {Permanent ID iil:note:56f7rxfx. License: CC-BY-4.0.},
}
Spotted a mistake? Use the MCP feedback tool or email hello@iinventedlight.com. Or Report a correction (no account needed).
Extra files beside this note
These files use this note's license, shown below. Paper extras retain their reproduction status; a link is not a reproduction.
- rust-derivable-traits.schema.json (schema; CC-BY-4.0)
- rust-derivable-traits.table.json (table; CC-BY-4.0)
For language models and agents: start at /llms.txt | /agents.md | /.well-known/agent-library.json. This page in Markdown: /library/notes/rust-derivable-traits.md.