Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clarify first matching arm and all possible values #1395

Merged
merged 1 commit into from
Dec 7, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/flow_control/match.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# match

Rust provides pattern matching via the `match` keyword, which can be used like
a C `switch`.
a C `switch`. The first matching arm is evaluated and all possible values must be
covered.

```rust,editable
fn main() {
Expand All @@ -14,10 +15,12 @@ fn main() {
1 => println!("One!"),
// Match several values
2 | 3 | 5 | 7 | 11 => println!("This is a prime"),
// TODO ^ Try adding 13 to the list of prime values
// Match an inclusive range
13..=19 => println!("A teen"),
// Handle the rest of cases
_ => println!("Ain't special"),
// TODO ^ Try commenting out this catch-all arm
}

let boolean = true;
Expand Down