Common traits: Debug, Display, Clone, Copy, PartialEq, Default, From/Into. Derive macros auto-implement many for structs and enums.
Derive
#[derive(Debug, Clone, PartialEq)]
struct User { name: String }
Important interview questions and answers
- Q: Copy vs Clone?
A: Copy is implicit bitwise duplicate for small types; Clone explicit duplication that may heap-allocate.
Self-check
- Which derive enables {:?} printing?
- Can every type be Copy?