Skip to content

Commit 124508d

Browse files
committed
auto merge of #18340 : chastell/rust/guide_closures_fixes, r=steveklabnik
Some minor wording fixes to the Closures chapter; my brain tripped a few times when reading it, so I tried to come up with something a bit smoother. I’m not a native speaker, so please do review this critically.
2 parents 1effc9e + 16bae69 commit 124508d

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

src/doc/guide.md

+12-12
Original file line numberDiff line numberDiff line change
@@ -4061,8 +4061,8 @@ syntax.
40614061

40624062
# Closures
40634063

4064-
So far, we've made lots of functions in Rust. But we've given them all names.
4065-
Rust also allows us to create anonymous functions too. Rust's anonymous
4064+
So far, we've made lots of functions in Rust, but we've given them all names.
4065+
Rust also allows us to create anonymous functions. Rust's anonymous
40664066
functions are called **closure**s. By themselves, closures aren't all that
40674067
interesting, but when you combine them with functions that take closures as
40684068
arguments, really powerful things are possible.
@@ -4091,7 +4091,7 @@ don't need to declare one. This is different from named functions, which
40914091
default to returning unit (`()`).
40924092

40934093
There's one big difference between a closure and named functions, and it's in
4094-
the name: a closure "closes over its environment." What's that mean? It means
4094+
the name: a closure "closes over its environment." What does that mean? It means
40954095
this:
40964096

40974097
```{rust}
@@ -4107,8 +4107,8 @@ fn main() {
41074107
The `||` syntax means this is an anonymous closure that takes no arguments.
41084108
Without it, we'd just have a block of code in `{}`s.
41094109

4110-
In other words, a closure has access to variables in the scope that it's
4111-
defined. The closure borrows any variables that it uses. This will error:
4110+
In other words, a closure has access to variables in the scope where it's
4111+
defined. The closure borrows any variables it uses, so this will error:
41124112

41134113
```{rust,ignore}
41144114
fn main() {
@@ -4132,7 +4132,7 @@ let p = proc() { x * x };
41324132
println!("{}", p()); // prints 25
41334133
```
41344134

4135-
Procs have a big difference from closures: they may only be called once. This
4135+
There is a big difference between procs and closures: procs may only be called once. This
41364136
will error when we try to compile:
41374137

41384138
```{rust,ignore}
@@ -4225,10 +4225,10 @@ before. And we pass in our `x` argument to each one. Hence 'twice.'
42254225
If you do the math, `(5 * 5) + (5 * 5) == 50`, so that's the output we get.
42264226

42274227
Play around with this concept until you're comfortable with it. Rust's standard
4228-
library uses lots of closures, where appropriate, so you'll be using
4228+
library uses lots of closures where appropriate, so you'll be using
42294229
this technique a lot.
42304230

4231-
If we didn't want to give `square` a name, we could also just define it inline.
4231+
If we didn't want to give `square` a name, we could just define it inline.
42324232
This example is the same as the previous one:
42334233

42344234
```{rust}
@@ -4256,12 +4256,12 @@ fn main() {
42564256
}
42574257
```
42584258

4259-
Doing this is not particularly common, but every once in a while, it's useful.
4259+
Doing this is not particularly common, but it's useful every once in a while.
42604260

42614261
That's all you need to get the hang of closures! Closures are a little bit
4262-
strange at first, but once you're used to using them, you'll miss them in any
4263-
language that doesn't have them. Passing functions to other functions is
4264-
incredibly powerful. Next, let's look at one of those things: iterators.
4262+
strange at first, but once you're used to them, you'll miss them
4263+
in other languages. Passing functions to other functions is
4264+
incredibly powerful, as you will see in the following chapter about iterators.
42654265

42664266
# Iterators
42674267

0 commit comments

Comments
 (0)