diff options
| author | Alexander Bliskovsky <alexander.bliskovsky@gmail.com> | 2015-02-22 20:06:25 -0500 |
|---|---|---|
| committer | Alexander Bliskovsky <alexander.bliskovsky@gmail.com> | 2015-02-22 20:26:54 -0500 |
| commit | 9f2b0671f88b2cc6bb73575db47d265dbb246e34 (patch) | |
| tree | fca232f75ce99921aad0c7d2165e67245b846e1f /src | |
| parent | 72eaf2c30e846b3d14c520c0c7638b2b16bf8c73 (diff) | |
| download | rust-9f2b0671f88b2cc6bb73575db47d265dbb246e34.tar.gz rust-9f2b0671f88b2cc6bb73575db47d265dbb246e34.zip | |
Fixed erroneous statements in iterators.md.
Diffstat (limited to 'src')
| -rw-r--r-- | src/doc/trpl/iterators.md | 13 |
1 files changed, 5 insertions, 8 deletions
diff --git a/src/doc/trpl/iterators.md b/src/doc/trpl/iterators.md index 943dbad35d7..33dc1ba07ca 100644 --- a/src/doc/trpl/iterators.md +++ b/src/doc/trpl/iterators.md @@ -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. @@ -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`: |
