@@ -4418,7 +4418,7 @@ see why consumers matter.
4418
4418
4419
4419
As we've said before, an iterator is something that we can call the ` .next() `
4420
4420
method on repeatedly, and it gives us a sequence of things. Because you need
4421
- to call the method, this means that iterators are ** lazy** . This code, for
4421
+ to call the method, this means that iterators can be ** lazy** and don't need to generate all of the values upfront . This code, for
4422
4422
example, does not actually generate the numbers ` 1-100 ` , and just creates a
4423
4423
value that represents the sequence:
4424
4424
@@ -4427,7 +4427,7 @@ let nums = range(1i, 100i);
4427
4427
```
4428
4428
4429
4429
Since we didn't do anything with the range, it didn't generate the sequence.
4430
- Once we add the consumer:
4430
+ Let's add the consumer:
4431
4431
4432
4432
``` {rust}
4433
4433
let nums = range(1i, 100i).collect::<Vec<int>>();
@@ -4456,8 +4456,8 @@ std::iter::count(1i, 5i);
4456
4456
```
4457
4457
4458
4458
This iterator counts up from one, adding five each time. It will give
4459
- you a new integer every time, forever. Well , technically, until the
4460
- maximum number that an ` int ` can represent . But since iterators are lazy,
4459
+ you a new integer every time, forever (well , technically, until it reaches the
4460
+ maximum number representable by an ` int ` ) . But since iterators are lazy,
4461
4461
that's okay! You probably don't want to use ` collect() ` on it, though...
4462
4462
4463
4463
That's enough about iterators. Iterator adapters are the last concept
@@ -5199,8 +5199,8 @@ to do something that it can't currently do? You may be able to write a macro
5199
5199
to extend Rust's capabilities.
5200
5200
5201
5201
You've already used one macro extensively: ` println! ` . When we invoke
5202
- a Rust macro, we need to use the exclamation mark (` ! ` ). There's two reasons
5203
- that this is true : the first is that it makes it clear when you're using a
5202
+ a Rust macro, we need to use the exclamation mark (` ! ` ). There are two reasons
5203
+ why this is so : the first is that it makes it clear when you're using a
5204
5204
macro. The second is that macros allow for flexible syntax, and so Rust must
5205
5205
be able to tell where a macro starts and ends. The ` !(...) ` helps with this.
5206
5206
@@ -5215,7 +5215,7 @@ println!("x is: {}", x);
5215
5215
5216
5216
The ` println! ` macro does a few things:
5217
5217
5218
- 1 . It parses the string to find any ` {} ` s
5218
+ 1 . It parses the string to find any ` {} ` s.
5219
5219
2 . It checks that the number of ` {} ` s matches the number of other arguments.
5220
5220
3 . It generates a bunch of Rust code, taking this in mind.
5221
5221
@@ -5224,8 +5224,8 @@ Rust will generate code that takes all of the types into account. If
5224
5224
` println! ` was a function, it could still do this type checking, but it
5225
5225
would happen at run time rather than compile time.
5226
5226
5227
- We can check this out using a special flag to ` rustc ` . This code, in a file
5228
- ` print.rs ` :
5227
+ We can check this out using a special flag to ` rustc ` . Put this code in a file
5228
+ called ` print.rs ` :
5229
5229
5230
5230
``` {rust}
5231
5231
fn main() {
@@ -5234,7 +5234,7 @@ fn main() {
5234
5234
}
5235
5235
```
5236
5236
5237
- Can have its macros expanded like this: ` rustc print.rs --pretty=expanded ` , will
5237
+ You can have the macros expanded like this: ` rustc print.rs --pretty=expanded ` – which will
5238
5238
give us this huge result:
5239
5239
5240
5240
``` {rust,ignore}
@@ -5273,12 +5273,12 @@ invoke the `println_args` function with the generated arguments.
5273
5273
This is the code that Rust actually compiles. You can see all of the extra
5274
5274
information that's here. We get all of the type safety and options that it
5275
5275
provides, but at compile time, and without needing to type all of this out.
5276
- This is how macros are powerful. Without them, you would need to type all of
5277
- this by hand to get a type checked ` println ` .
5276
+ This is how macros are powerful: without them you would need to type all of
5277
+ this by hand to get a type- checked ` println ` .
5278
5278
5279
5279
For more on macros, please consult [ the Macros Guide] ( guide-macros.html ) .
5280
- Macros are a very advanced and still slightly experimental feature, but don't
5281
- require a deep understanding to call , since they look just like functions. The
5280
+ Macros are a very advanced and still slightly experimental feature, but they don't
5281
+ require a deep understanding to be called , since they look just like functions. The
5282
5282
Guide can help you if you want to write your own.
5283
5283
5284
5284
# Unsafe
@@ -5295,8 +5295,8 @@ keyword, which indicates that the function may not behave properly.
5295
5295
5296
5296
Second, if you'd like to create some sort of shared-memory data structure, Rust
5297
5297
won't allow it, because memory must be owned by a single owner. However, if
5298
- you're planning on making access to that shared memory safe, such as with a
5299
- mutex, _ you_ know that it's safe, but Rust can't know. Writing an ` unsafe `
5298
+ you're planning on making access to that shared memory safe – such as with a
5299
+ mutex – _ you_ know that it's safe, but Rust can't know. Writing an ` unsafe `
5300
5300
block allows you to ask the compiler to trust you. In this case, the _ internal_
5301
5301
implementation of the mutex is considered unsafe, but the _ external_ interface
5302
5302
we present is safe. This allows it to be effectively used in normal Rust, while
0 commit comments