From 770f0e95a189e84491845ab1378eb3bc3c896f62 Mon Sep 17 00:00:00 2001 From: Johann Hofmann Date: Mon, 11 May 2015 02:03:37 +0200 Subject: [PATCH 1/2] Add if let expressions example --- src/doc/reference.md | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/doc/reference.md b/src/doc/reference.md index 16fdcfa301392..89f74d8d87afa 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 From 6a19046423b49672bc71eb07149ae9ef32bc8af5 Mon Sep 17 00:00:00 2001 From: Johann Date: Mon, 11 May 2015 02:40:02 +0200 Subject: [PATCH 2/2] Four spaces indent, rephrasing --- src/doc/reference.md | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/doc/reference.md b/src/doc/reference.md index 89f74d8d87afa..e6afa695b2c68 100644 --- a/src/doc/reference.md +++ b/src/doc/reference.md @@ -3066,12 +3066,15 @@ block will execute, otherwise flow proceeds to the first `else` block that follo ``` let dish = ("Ham", "Eggs"); -if let ("Bacon", b) = dish { // will not execute because let is refuted - println!("Bacon is served with {}", b); + +// this body will be skipped because the pattern is refuted +if let ("Bacon", b) = dish { + println!("Bacon is served with {}", b); } -if let ("Ham", b) = dish { // will execute - println!("Ham is served with {}", b); +// this body will execute +if let ("Ham", b) = dish { + println!("Ham is served with {}", b); } ```