Skip to content

trpl: Few minor fixes (wording, formatting) #28889

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 8, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions src/doc/trpl/iterators.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,12 @@ loop is just a handy way to write this `loop`/`match`/`break` construct.
`for` loops aren't the only thing that uses iterators, however. Writing your
own iterator involves implementing the `Iterator` trait. While doing that is
outside of the scope of this guide, Rust provides a number of useful iterators
to accomplish various tasks. Before we talk about those, we should talk about a
Rust anti-pattern. And that's using ranges like this.
to accomplish various tasks. But first, a few notes about limitations of ranges.

Yes, we just talked about how ranges are cool. But ranges are also very
primitive. For example, if you needed to iterate over the contents of a vector,
you may be tempted to write this:
Ranges are very primitive, and we often can use better alternatives. Consider
following Rust anti-pattern: using ranges to emulate a C-style `for` loop. Let’s
suppose you needed to iterate over the contents of a vector. You may be tempted
to write this:

```rust
let nums = vec![1, 2, 3];
Expand Down Expand Up @@ -281,8 +281,8 @@ If you are trying to execute a closure on an iterator for its side effects,
just use `for` instead.

There are tons of interesting iterator adapters. `take(n)` will return an
iterator over the next `n` elements of the original iterator. Let's try it out with our infinite
iterator from before:
iterator over the next `n` elements of the original iterator. Let's try it out
with an infinite iterator:

```rust
for i in (1..).take(5) {
Expand Down
8 changes: 4 additions & 4 deletions src/doc/trpl/lifetimes.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,11 @@ With that in mind, let’s learn about lifetimes.
Lending out a reference to a resource that someone else owns can be
complicated. For example, imagine this set of operations:

- I acquire a handle to some kind of resource.
- I lend you a reference to the resource.
- I decide I’m done with the resource, and deallocate it, while you still have
1. I acquire a handle to some kind of resource.
2. I lend you a reference to the resource.
3. I decide I’m done with the resource, and deallocate it, while you still have
your reference.
- You decide to use the resource.
4. You decide to use the resource.

Uh oh! Your reference is pointing to an invalid resource. This is called a
dangling pointer or ‘use after free’, when the resource is memory.
Expand Down