about summary refs log tree commit diff
path: root/src/doc/reference.md
diff options
context:
space:
mode:
authorJohann Hofmann <git@johann-hofmann.com>2015-05-11 02:03:37 +0200
committerJohann Hofmann <git@johann-hofmann.com>2015-05-11 02:03:37 +0200
commit770f0e95a189e84491845ab1378eb3bc3c896f62 (patch)
treeda4a6173f340e379c4996e1ac8088b39fec00277 /src/doc/reference.md
parent750f2c63f2737305d33288303cdecb7a470a7922 (diff)
downloadrust-770f0e95a189e84491845ab1378eb3bc3c896f62.tar.gz
rust-770f0e95a189e84491845ab1378eb3bc3c896f62.zip
Add if let expressions example
Diffstat (limited to 'src/doc/reference.md')
-rw-r--r--src/doc/reference.md11
1 files changed, 11 insertions, 0 deletions
diff --git a/src/doc/reference.md b/src/doc/reference.md
index 16fdcfa3013..89f74d8d87a 100644
--- a/src/doc/reference.md
+++ b/src/doc/reference.md
@@ -3064,6 +3064,17 @@ of a condition expression it expects a refutable let statement. If the value of
 expression on the right hand side of the let statement matches the pattern, the corresponding
 block will execute, otherwise flow proceeds to the first `else` block that follows.
 
+```
+let dish = ("Ham", "Eggs");
+if let ("Bacon", b) = dish { // will not execute because let is refuted
+  println!("Bacon is served with {}", b);
+}
+
+if let ("Ham", b) = dish { // will execute
+  println!("Ham is served with {}", b);
+}
+```
+
 ### While let loops
 
 A `while let` loop is semantically identical to a `while` loop but in place of a