Pattern matching in Rust compares a value against a series of patterns to execute specific code blocks based on the match. It is primarily implemented using the match control flow operator, which ensures all possible cases are handled. The match expression evaluates the value and runs the code block corresponding to the first pattern that fits.
fn main() {
let number = 13;
match number {
1 => println!("One"),
2 | 3 | 5 | 7 | 11 => println!("Prime number"),
_ => println!("Something else"),
}
}