Skip to content

Commit a5344b8

Browse files
authored
Add another code snippet
1 parent 76f74ab commit a5344b8

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

first_steps/match.rs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
fn main() {
2+
let number = 13;
3+
4+
println!("Tell me about {}", number);
5+
match number {
6+
// Match a single value
7+
1 => println!("One!"),
8+
// Match several values
9+
2 | 3 | 5 | 7 | 11 => println!("This is a prime"),
10+
// Match an inclusive range
11+
13...19 => println!("A teen"),
12+
// Handle the rest of cases
13+
_ => println!("Ain't special"),
14+
}
15+
16+
let boolean = true;
17+
// Match is an expression too
18+
let binary = match boolean {
19+
// The arms of a match must cover all the possible values
20+
false => 0,
21+
true => 1,
22+
};
23+
24+
println!("{} -> {}", boolean, binary);
25+
}

0 commit comments

Comments
 (0)