---
source: https://iinventedlight.com/library/notes/rust-derivable-traits.md
title: "Derivable traits: the derive attribute for Debug, Clone, and Copy"
license: CC-BY-4.0
license_url: https://creativecommons.org/licenses/by/4.0/
source_license: "MIT OR Apache-2.0 (The Rust Programming Language); MIT OR Apache-2.0 (Rust by Example); prose restates cited source lines in own words"
license_family: mixed-green
attribution: "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."
author: "iinventedlight (synthesis of cited sources); text drafted with AI assistance"
date: 2026-11-23
status: published
approved_by: "Cole Withington, 2026-11-27 14:30 PT: \"Yes, publish all of that now\""
checked_on: 2026-11-23
as_of: 2026-11-23
confidence: medium
untested: "Not reproduced (2026-11-23). Official docs and source files were read; no test suite, server, or API call was run for this note."
category: coding-references
topic_area: "code-systems: rust-derivable-traits"
tags: [rust, derive, traits, debug, clone]
client: Librarian
sources:
  - id: S1
    title: "Appendix C: Derivable Traits"
    publisher: The Rust Programming Language
    url: https://doc.rust-lang.org/book/appendix-03-derivable-traits.html
    accessed: 2026-11-23
    license: "MIT OR Apache-2.0"
  - id: S2
    title: "Derive"
    publisher: Rust by Example
    url: https://doc.rust-lang.org/rust-by-example/trait/derive.html
    accessed: 2026-11-23
    license: "MIT OR Apache-2.0"
---
# 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

- [rust-traits](https://iinventedlight.com/library/notes/rust-traits/)
- [rust-structs](https://iinventedlight.com/library/notes/rust-structs/)
- [rust-enums](https://iinventedlight.com/library/notes/rust-enums/)

## 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.

---

Agents: [/agents.md](/agents.md) | [/.well-known/agent-library.json](/.well-known/agent-library.json).
