23.06 Pattern Matching
Pattern Matching
Overview
Pattern matching in Rust is a powerful feature used to destructure and match values.
Topics
- match Expressions
- if let and while let
- Destructuring Structs, Enums, and Tuples
Examples
let number = 7;
match number {
1 => println!("One"),
2 | 3 | 5 | 7 => println!("Prime"),
_ => println!("Other"),
}
if let Some(x) = Some(10) {
println!("Matched: {}", x);
}
while let Some(x) = Some(5) {
println!("Looping with: {}", x);
break;
}