Struct — custom type with fields (single shape). Enum — type with multiple variants.
Struct:
impl blocks.1struct Player {2 name: String,3 score: u32,4 active: bool,5}67impl Player {8 fn new(name: &str) -> Self {9 Self { name: name.to_string(), score: 0, active: true }10 }11}
Enum:
match ensures all cases handled.1enum Direction {2 North,3 South,4 East,5 West,6}78fn turn(dir: Direction) -> Direction {9 match dir {10 Direction::North => Direction::East,11 Direction::East => Direction::South,12 Direction::South => Direction::West,13 Direction::West => Direction::North,14 }15}
When to use:
Common mistakes:
match — compiler enforces exhaustiveness.Debug, Clone.