@@ -91,11 +91,11 @@ for num in &nums {
91
91
```
92
92
93
93
Now we're explicitly dereferencing ` num ` . Why does ` &nums ` give us
94
- references? Because we asked it to with ` & ` . If we had not had the
95
- ` & ` , ` nums ` would have been moved into the ` for ` loop and consumed,
96
- and we we would no longer be able to access ` nums ` afterward. With
97
- references, we're just borrowing a reference to the data, and so it's
98
- just passing a reference, without needing to do the move.
94
+ references? Firstly, because we explicitly asked it to with
95
+ ` & ` . Secondly, if it gave us the data itself, we would have to be its
96
+ owner, which would involve making a copy of the data and giving us the
97
+ copy. With references, we're just borrowing a reference to the data,
98
+ and so it's just passing a reference, without needing to do the move.
99
99
100
100
So, now that we've established that ranges are often not what you want, let's
101
101
talk about what you do want instead.
@@ -242,9 +242,6 @@ for num in nums.iter() {
242
242
}
243
243
```
244
244
245
- Sometimes you need this functionality, but since for loops operate on the
246
- ` IntoIterator ` trait, calling ` .iter() ` is rarely necessary.
247
-
248
245
These two basic iterators should serve you well. There are some more
249
246
advanced iterators, including ones that are infinite. Like ` count ` :
250
247
0 commit comments