rust-by-practice/src/pattern-match/patterns.md

24 lines
483 B
Markdown
Raw Normal View History

# Patterns
2022-03-01 06:12:55 -06:00
🌟🌟 Using `|` to match several values.
```rust,editable
fn main() {}
fn match_number(n: i32) {
match n {
// match a single value
1 => println!("One!"),
// fill in the blank with `|`, DON'T use `..` ofr `..=`
__ => println!("match 2 -> 5"),
// match an inclusive range
6..=10 => {
println!("match 6 -> 10")
},
_ => {
println!("match 11 -> +infinite")
}
}
}
```