Struct — custom type with named fields (single shape). Enum — type with multiple possible variants.
Struct:
impl blocks.1// Named fields2struct User {3 name: String,4 email: String,5 active: bool,6}78// Tuple struct9struct Point(f64, f64);1011// Unit struct12struct Marker;
Enum:
match for exhaustive pattern matching.1enum TrafficLight {2 Red,3 Yellow,4 Green,5}67enum Message {8 Quit,9 Move { x: i32, y: i32 },10 Write(String),11 ChangeColor(i32, i32, i32),12}
When to use:
Common mistakes:
match — compiler enforces exhaustiveness.#[derive()] for auto-implementation of traits.