Rust’s standard library defines a set of traits that types opt into to gain shared behaviour — formatting, cloning, comparison, iteration, conversion. Many can be derived; others must be written by hand. This tool is a searchable reference covering each trait’s required methods, derive support, and blanket implementations.
How it works
A trait declares method signatures; an impl Trait for Type block supplies
them. Some methods are required (you must provide them) and some are
provided (default implementations you may override). The reference notes,
for each trait:
- Required methods — the minimum you must implement.
- Derivable — whether
#[derive(...)]can generate the impl when all fields cooperate. - Blanket impls — automatic implementations, such as
IntofromFrom, orToStringfromDisplay.
Worked example
#[derive(Debug, Clone, PartialEq, Eq, Hash, Default)]
struct Point { x: i32, y: i32 }
// Display cannot be derived — write it by hand:
use std::fmt;
impl fmt::Display for Point {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "({}, {})", self.x, self.y)
}
}
// From gives Into for free via a blanket impl:
impl From<(i32, i32)> for Point {
fn from((x, y): (i32, i32)) -> Self { Point { x, y } }
}
let p: Point = (1, 2).into(); // Into<Point> exists automatically
Notes
- Implementing
Displayautomatically gives youToString(and thus.to_string()) through a blanket impl — never implementToStringdirectly. Eq,Ord, andHashare consistency-marker contracts: deriving them keeps==, ordering, and hashing in agreement, whichHashMap/BTreeMaprely on.Dropcannot be derived and cannot be called manually; the compiler invokes it when a value goes out of scope. Usestd::mem::dropto drop early.Derefpowers smart pointers likeBoxandRc; abusing it for inheritance is discouraged.