Skip to content

Commit 4711ac3

Browse files
committed
Auto merge of #38436 - bluecereal:patch-1, r=frewsxcv
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.
2 parents a3da24b + fb7f211 commit 4711ac3

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

src/doc/book/if-let.md

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
% if let
22

3-
`if let` allows you to combine `if` and `let` together to reduce the overhead
4-
of certain kinds of pattern matches.
3+
`if let` permits [patterns][pattern] matching within the condition of an [if][if] statement.
4+
This allows us to reduce the overhead of certain kinds of [pattern][patterns] matches
5+
and express them in a more convenient way.
56

67
For example, let’s say we have some sort of `Option<T>`. We want to call a function
78
on it if it’s `Some<T>`, but do nothing if it’s `None`. That looks like this:
@@ -80,3 +81,4 @@ while let Some(x) = v.pop() {
8081
```
8182

8283
[patterns]: patterns.html
84+
[if]: if.html

0 commit comments

Comments
 (0)