diff --git a/matching/Cargo.toml b/matching/Cargo.toml new file mode 100644 index 0000000..ef2f3c7 --- /dev/null +++ b/matching/Cargo.toml @@ -0,0 +1,9 @@ +[package] +name = "matching" +version = "0.1.0" +authors = ["gbrochar "] +edition = "2018" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] diff --git a/matching/src/main.rs b/matching/src/main.rs new file mode 100644 index 0000000..5cce451 --- /dev/null +++ b/matching/src/main.rs @@ -0,0 +1,35 @@ +struct Point { + x: i32, + y: i32, +} + +fn main() { + let mut stack = Vec::new(); + + stack.push(1); + stack.push(2); + stack.push(3); + + while let Some(top) = stack.pop() { + println!("{}", top); + } + + let p = Point { x: 0, y: 7 }; + + match p { + Point { x, y: 0 } => println!("On the x axis at {}", x), + Point { x: 0, y } => println!("On the y axis at {}", y), + Point { x, y } => println!("On neither axis: ({}, {})", x, y), + } + + let ((feet, inches), Point { x, y }) = ((3, 10), Point { x: 3, y: -10 }); + println!("{}, {}, {}, {}", feet, inches, x, y); + + let x = 4; + let y = false; + + match x { + 4 | 5 | 6 if y => println!("yes"), + _ => println!("no"), + } +} \ No newline at end of file