Traits are Rust's mechanism for describing shared behavior. A trait declares a set of methods that a type must implement, much like an interface in object-oriented languages, and a type implements a trait with `impl Trait for Type { ... }`. Once a trait is implemented, the type can be used anywhere the trait is required, which makes traits the foundation of Rust's polymorphism.
Generic functions and types use type parameters so that the same code can operate on many concrete types. To guarantee that a generic parameter supports the operations the function needs, you add trait bounds — either inline with `T: Trait` or with a `where` clause. At compile time, Rust performs monomorphization, generating a specialized copy of the code for each concrete type that is actually used, so generic code carries zero runtime cost compared to hand-written per-type versions.
Many useful behaviors are expressed as traits that the compiler can implement for you automatically when you opt in with `#[derive(...)]`. `Debug` enables `{:?}` formatting for inspection; `Clone` provides an explicit `.clone()`; `Copy` allows implicit bitwise duplication for stack-only types like integers and booleans; `PartialEq` and `Eq` enable equality; `PartialOrd` and `Ord` enable ordering; and `Hash` enables use in hash-based collections. All `Copy` types must also implement `Clone`, but not vice versa.
Two additional traits round out the common vocabulary. `From