You've already forked comprehensive-rust
mirror of
https://github.com/google/comprehensive-rust.git
synced 2025-12-22 14:48:45 +02:00
Publish Comprehensive Rust 🦀
This commit is contained in:
21
src/pattern-matching.md
Normal file
21
src/pattern-matching.md
Normal file
@@ -0,0 +1,21 @@
|
||||
# Pattern Matching
|
||||
|
||||
The `match` keyword let you match a value against one or more _patterns_. The
|
||||
comparisons are done from top to bottom and the first match wins.
|
||||
|
||||
The patterns can be simple values, similarly to `switch` in C and C++:
|
||||
|
||||
```rust,editable
|
||||
fn main() {
|
||||
let input = 'x';
|
||||
|
||||
match input {
|
||||
'q' => println!("Quitting"),
|
||||
'a' | 's' | 'w' | 'd' => println!("Moving around"),
|
||||
'0'..='9' => println!("Number input"),
|
||||
_ => println!("Something else"),
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
The `_` pattern is a wildcard pattern which matches any value.
|
||||
Reference in New Issue
Block a user