← Rust Programming learning pathRust Programming · Module 5 of 10
Structs, enums and pattern matching
Model data with structs and enums, and match on them.
📖 Key ideas
- struct User { name: String, age: u32 }.
- impl blocks add methods: impl User { fn greet(&self) {} }.
- Enums can hold data: enum Shape { Circle(f64), Rect(f64, f64) }.
- match must handle every case.
- 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