Skip to content

Commit 4eedd87

Browse files
committed
Guide: Closures: minor wording fixes
1 parent f168c12 commit 4eedd87

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

src/doc/guide.md

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4010,8 +4010,8 @@ syntax.
40104010

40114011
# Closures
40124012

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

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

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

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

40624062
```{rust,ignore}
40634063
fn main() {
@@ -4081,7 +4081,7 @@ let p = proc() { x * x };
40814081
println!("{}", p()); // prints 25
40824082
```
40834083

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

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

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

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

41834183
```{rust}
@@ -4205,12 +4205,12 @@ fn main() {
42054205
}
42064206
```
42074207

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

42104210
That's all you need to get the hang of closures! Closures are a little bit
4211-
strange at first, but once you're used to using them, you'll miss them in any
4212-
language that doesn't have them. Passing functions to other functions is
4213-
incredibly powerful. Next, let's look at one of those things: iterators.
4211+
strange at first, but once you're used to them, you'll miss them
4212+
in other languages. Passing functions to other functions is
4213+
incredibly powerful; let's look at one of such situations: iterators.
42144214

42154215
# Iterators
42164216

0 commit comments

Comments
 (0)