From 4495f7e51e1d8e42440419bf97dfd04b28b544c4 Mon Sep 17 00:00:00 2001 From: bluecereal Date: Fri, 16 Dec 2016 22:28:27 -0500 Subject: [PATCH 1/3] Update if-let.md Calling if-let a combination of if and let is confusing, as some may be led to believe that it's a literal combination, instead of syntactic sugar added to the language as a convenience. What's there to stop someone from thinking if-let is just if and let together? I do think this article does a good job of implying what's really going on; however, I was only able to notice this after I had begun to understand if/while-let statements, courtesy of the Rust IRC chat. Basically, this article lacks the clarity and explicitness an inexperienced programmer like me needs in order to understand the contents fully. This is shown by my inability to understand the if-let concept from this page of the Book alone. I think convenience, sugar, and (if-let != if + let) should all be made mention of in a clear, explicit manner. I lack confidence in my understanding of this issue, so I wrote just enough to hopefully get my thoughts across. --- src/doc/book/if-let.md | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/doc/book/if-let.md b/src/doc/book/if-let.md index 9afe5fa826d29..35808b0ed9f06 100644 --- a/src/doc/book/if-let.md +++ b/src/doc/book/if-let.md @@ -1,7 +1,9 @@ % if let -`if let` allows you to combine `if` and `let` together to reduce the overhead -of certain kinds of pattern matches. +`if let` is a figurative combination of `if` and `let`. `if let` does not literally +mean `if` + `let` to the compiler; it has its own special meaning,which was added for +convenience and as a way to reduce the overhead of certain kinds of pattern matches. + For example, let’s say we have some sort of `Option`. We want to call a function on it if it’s `Some`, but do nothing if it’s `None`. That looks like this: From ebf07da0a502acba5fe29b085c3244834e4e3bf5 Mon Sep 17 00:00:00 2001 From: bluecereal Date: Sat, 21 Jan 2017 02:24:48 -0500 Subject: [PATCH 2/3] Update if-let.md --- src/doc/book/if-let.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/doc/book/if-let.md b/src/doc/book/if-let.md index 35808b0ed9f06..2231dddf204de 100644 --- a/src/doc/book/if-let.md +++ b/src/doc/book/if-let.md @@ -1,9 +1,8 @@ % if let -`if let` is a figurative combination of `if` and `let`. `if let` does not literally -mean `if` + `let` to the compiler; it has its own special meaning,which was added for -convenience and as a way to reduce the overhead of certain kinds of pattern matches. - +`if let` allows us to match [patterns][patterns] within the condition of an [if][if]. +As a consequence, we reduce the overhead of certain kinds of [pattern][patterns] matches +and express them in a more convenient way. For example, let’s say we have some sort of `Option`. We want to call a function on it if it’s `Some`, but do nothing if it’s `None`. That looks like this: @@ -82,3 +81,4 @@ while let Some(x) = v.pop() { ``` [patterns]: patterns.html +[if]: if.html From fb7f211c0c0723c84d9f5da58e80a7766478b616 Mon Sep 17 00:00:00 2001 From: bluecereal Date: Sun, 5 Feb 2017 20:20:43 -0500 Subject: [PATCH 3/3] Update if-let.md --- src/doc/book/if-let.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/doc/book/if-let.md b/src/doc/book/if-let.md index 2231dddf204de..e76149ad27050 100644 --- a/src/doc/book/if-let.md +++ b/src/doc/book/if-let.md @@ -1,7 +1,7 @@ % if let -`if let` allows us to match [patterns][patterns] within the condition of an [if][if]. -As a consequence, we reduce the overhead of certain kinds of [pattern][patterns] matches +`if let` permits [patterns][pattern] matching within the condition of an [if][if] statement. +This allows us to reduce the overhead of certain kinds of [pattern][patterns] matches and express them in a more convenient way. For example, let’s say we have some sort of `Option`. We want to call a function