@@ -135,7 +135,7 @@ invalidation*. As long as an iterator is still in scope, the compiler will preve
135
135
modification of the container through another handle.
136
136
137
137
~~~
138
- let mut xs = [1 , 2, 3];
138
+ let mut xs = [1i , 2, 3];
139
139
{
140
140
let _it = xs.iter();
141
141
@@ -155,16 +155,16 @@ example, the `fold` method will accumulate the items yielded by an `Iterator`
155
155
into a single value:
156
156
157
157
~~~
158
- let xs = [1 , 9, 2, 3, 14, 12];
158
+ let xs = [1i , 9, 2, 3, 14, 12];
159
159
let result = xs.iter().fold(0, |accumulator, item| accumulator - *item);
160
160
assert_eq!(result, -41);
161
161
~~~
162
162
163
163
Most adaptors return an adaptor object implementing the ` Iterator ` trait itself:
164
164
165
165
~~~
166
- let xs = [1 , 9, 2, 3, 14, 12];
167
- let ys = [5 , 2, 1, 8];
166
+ let xs = [1i , 9, 2, 3, 14, 12];
167
+ let ys = [5i , 2, 1, 8];
168
168
let sum = xs.iter().chain(ys.iter()).fold(0, |a, b| a + *b);
169
169
assert_eq!(sum, 57);
170
170
~~~
@@ -180,8 +180,8 @@ iterator adaptor named `fuse()` is provided. This returns an iterator that will
180
180
never call its underlying iterator again once ` None ` has been returned:
181
181
182
182
~~~
183
- let xs = [1 ,2,3,4,5];
184
- let mut calls = 0 ;
183
+ let xs = [1i ,2,3,4,5];
184
+ let mut calls = 0i ;
185
185
186
186
{
187
187
let it = xs.iter().scan((), |_, x| {
@@ -209,11 +209,11 @@ assert_eq!(calls, 3);
209
209
The function ` range ` (or ` range_inclusive ` ) allows to simply iterate through a given range:
210
210
211
211
~~~
212
- for i in range(0 , 5) {
212
+ for i in range(0i , 5) {
213
213
print!("{} ", i) // prints "0 1 2 3 4"
214
214
}
215
215
216
- for i in std::iter::range_inclusive(0 , 5) { // needs explicit import
216
+ for i in std::iter::range_inclusive(0i , 5) { // needs explicit import
217
217
print!("{} ", i) // prints "0 1 2 3 4 5"
218
218
}
219
219
~~~
@@ -238,7 +238,7 @@ For loops are *often* used with a temporary iterator object, as above. They can
238
238
also advance the state of an iterator in a mutable location:
239
239
240
240
~~~
241
- let xs = [1 , 2, 3, 4, 5];
241
+ let xs = [1i , 2, 3, 4, 5];
242
242
let ys = ["foo", "bar", "baz", "foobar"];
243
243
244
244
// create an iterator yielding tuples of elements from both vectors
@@ -265,7 +265,7 @@ assert!(it.next().is_none());
265
265
Iterators offer generic conversion to containers with the ` collect ` adaptor:
266
266
267
267
~~~
268
- let xs = [0 , 1, 1, 2, 3, 5, 8];
268
+ let xs = [0i , 1, 1, 2, 3, 5, 8];
269
269
let ys = xs.iter().rev().skip(1).map(|&x| x * 2).collect::<Vec<int>>();
270
270
assert_eq!(ys, vec![10, 6, 4, 2, 2, 0]);
271
271
~~~
@@ -347,7 +347,7 @@ A `DoubleEndedIterator` can have its direction changed with the `rev` adaptor,
347
347
returning another ` DoubleEndedIterator ` with ` next ` and ` next_back ` exchanged.
348
348
349
349
~~~
350
- let xs = [1 , 2, 3, 4, 5, 6];
350
+ let xs = [1i , 2, 3, 4, 5, 6];
351
351
let mut it = xs.iter();
352
352
println!("{}", it.next()); // prints `Some(1)`
353
353
println!("{}", it.next()); // prints `Some(2)`
@@ -363,8 +363,8 @@ The `chain`, `map`, `filter`, `filter_map` and `inspect` adaptors are
363
363
` DoubleEndedIterator ` implementations if the underlying iterators are.
364
364
365
365
~~~
366
- let xs = [1 , 2, 3, 4];
367
- let ys = [5 , 6, 7, 8];
366
+ let xs = [1i , 2, 3, 4];
367
+ let ys = [5i , 6, 7, 8];
368
368
let mut it = xs.iter().chain(ys.iter()).map(|&x| x * 2);
369
369
370
370
println!("{}", it.next()); // prints `Some(2)`
@@ -380,9 +380,9 @@ mutable references. It can be used to reverse a container in-place. Note that
380
380
the trailing underscore is a workaround for issue #5898 and will be removed.
381
381
382
382
~~~
383
- let mut ys = [1 , 2, 3, 4, 5];
383
+ let mut ys = [1i , 2, 3, 4, 5];
384
384
ys.mut_iter().reverse_();
385
- assert!(ys == [5 , 4, 3, 2, 1]);
385
+ assert!(ys == [5i , 4, 3, 2, 1]);
386
386
~~~
387
387
388
388
## Random-access iterators
@@ -395,8 +395,8 @@ The `chain` adaptor is an implementation of `RandomAccessIterator` if the
395
395
underlying iterators are.
396
396
397
397
~~~
398
- let xs = [1 , 2, 3, 4, 5];
399
- let ys = [7 , 9, 11];
398
+ let xs = [1i , 2, 3, 4, 5];
399
+ let ys = [7i , 9, 11];
400
400
let mut it = xs.iter().chain(ys.iter());
401
401
println!("{}", it.idx(0)); // prints `Some(1)`
402
402
println!("{}", it.idx(5)); // prints `Some(7)`
0 commit comments