Skip to content

Switch to &vector notation in the iterators chapter. #22612

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
Feb 23, 2015
Merged
Changes from 1 commit
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
Prev Previous commit
Fixed erroneous statements in iterators.md.
  • Loading branch information
jxcl committed Feb 23, 2015
commit 9f2b0671f88b2cc6bb73575db47d265dbb246e34
13 changes: 5 additions & 8 deletions src/doc/trpl/iterators.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,11 @@ for num in &nums {
```

Now we're explicitly dereferencing `num`. Why does `&nums` give us
references? Because we asked it to with `&`. If we had not had the
`&`, `nums` would have been moved into the `for` loop and consumed,
and we we would no longer be able to access `nums` afterward. With
references, we're just borrowing a reference to the data, and so it's
just passing a reference, without needing to do the move.
references? Firstly, because we explicitly asked it to with
`&`. Secondly, if it gave us the data itself, we would have to be its
owner, which would involve making a copy of the data and giving us the
copy. With references, we're just borrowing a reference to the data,
and so it's just passing a reference, without needing to do the move.

So, now that we've established that ranges are often not what you want, let's
talk about what you do want instead.
Expand Down Expand Up @@ -242,9 +242,6 @@ for num in nums.iter() {
}
```

Sometimes you need this functionality, but since for loops operate on the
`IntoIterator` trait, calling `.iter()` is rarely necessary.

These two basic iterators should serve you well. There are some more
advanced iterators, including ones that are infinite. Like `count`:

Expand Down