There was an error while loading. Please reload this page.
1 parent 76f74ab commit a5344b8Copy full SHA for a5344b8
first_steps/match.rs
@@ -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