← Rust Programming learning path
Rust Programming · Module 5 of 10

Structs, enums and pattern matching

Model data with structs and enums, and match on them.

📖 Key ideas

  1. struct User { name: String, age: u32 }.
  2. impl blocks add methods: impl User { fn greet(&self) {} }.
  3. Enums can hold data: enum Shape { Circle(f64), Rect(f64, f64) }.
  4. match must handle every case.
  5. if let handles one pattern concisely.
💡 Real-life example: match is a sorting machine that sends every item down exactly one correct chute.
structCustom data type with fields
implBlock defining methods
enumType with variants
matchExhaustive pattern matching