File tree Expand file tree Collapse file tree 2 files changed +39
-0
lines changed Expand file tree Collapse file tree 2 files changed +39
-0
lines changed Original file line number Diff line number Diff line change
1
+ [package ]
2
+ name = " c18_pattern_matching"
3
+ version = " 0.1.0"
4
+ edition = " 2021"
5
+
6
+ # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
7
+
8
+ [dependencies ]
Original file line number Diff line number Diff line change
1
+ fn main ( ) {
2
+ let mut x = Some ( 1 ) ;
3
+ //let mut x: Option<i32> = None;
4
+ println ! ( "i={:?}" , x) ;
5
+ //let x = ();
6
+ x = match x {
7
+ None => None ,
8
+ Some ( i) => Some ( i + 1 ) ,
9
+ } ;
10
+ println ! ( "i={:?}" , x) ;
11
+
12
+ println ! ( "Hello, world!" ) ;
13
+
14
+ let favorite_color: Option < & str > = None ;
15
+ let is_tuesday = false ;
16
+ let age: Result < u8 , _ > = "34" . parse ( ) ;
17
+
18
+ if let Some ( color) = favorite_color {
19
+ println ! ( "Using your favorite color, {color}, as the background" ) ;
20
+ } else if is_tuesday {
21
+ println ! ( "Tuesday is green day!" ) ;
22
+ } else if let Ok ( age) = age {
23
+ if age > 30 {
24
+ println ! ( "Using purple as the background color" ) ;
25
+ } else {
26
+ println ! ( "Using orange as the background color" ) ;
27
+ }
28
+ } else {
29
+ println ! ( "Using blue as the background color" ) ;
30
+ }
31
+ }
You can’t perform that action at this time.
0 commit comments