summaryrefslogtreecommitdiff
path: root/Pattern matching with a match expression.md
diff options
context:
space:
mode:
authorJasper Ras <jras@hostnet.nl>2025-08-03 22:29:47 +0200
committerJasper Ras <jras@hostnet.nl>2025-08-03 22:29:47 +0200
commit931eb0894e7cd3717f1218f0eb06382b11734c13 (patch)
treeb6ad9b0d98a8f26e496c91ad3f24d1c855b654df /Pattern matching with a match expression.md
parentaf98004d2cf437603f47f4224110a80d76d0d7de (diff)
vault backup: 2025-08-03 22:29:47
Diffstat (limited to 'Pattern matching with a match expression.md')
-rw-r--r--Pattern matching with a match expression.md13
1 files changed, 13 insertions, 0 deletions
diff --git a/Pattern matching with a match expression.md b/Pattern matching with a match expression.md
new file mode 100644
index 0000000..affc752
--- /dev/null
+++ b/Pattern matching with a match expression.md
@@ -0,0 +1,13 @@
+[[Rust]]
+
+This looks like a regular function call but then followed by a block of code. It is called a match expression. A match expression consists of arms, that are the pattern to match and the code to execute.
+
+For example if a function returns an enum it is a nice way to write each case, it is somewhat similar to a switch statement.
+
+```rust
+guess.cmp(&secret_number) {
+ Ordering::Less => println!("Too small!"),
+ Ordering::Greater => println!("Too big!"),
+ Ordering::Equal => println!("You win!!"),
+}
+```