File tree Expand file tree Collapse file tree 2 files changed +8
-4
lines changed
branches/snap-stage3/src/doc Expand file tree Collapse file tree 2 files changed +8
-4
lines changed Original file line number Diff line number Diff line change 1
1
---
2
2
refs/heads/master: 0b48001c28329392b26961eaf1c3ed293a352d6f
3
3
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
4
- refs/heads/snap-stage3: 0b5bc3314fa9bf768163828a8e38bac588936fe9
4
+ refs/heads/snap-stage3: 63718792df1214d0bf7b5a12508cc7301e3be665
5
5
refs/heads/try: f58aad6dce273570fb130b4df008ef9acd5a5be2
6
6
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
7
7
refs/heads/dist-snap: ba4081a5a8573875fed17545846f6f6902c8ba8d
Original file line number Diff line number Diff line change @@ -4601,20 +4601,24 @@ returns `true` or `false`. The new iterator `filter()` produces
4601
4601
only the elements that that closure returns ` true ` for:
4602
4602
4603
4603
``` {rust}
4604
- for i in range(1i, 100i).filter(|x| x % 2 == 0) {
4604
+ for i in range(1i, 100i).filter(|& x| x % 2 == 0) {
4605
4605
println!("{}", i);
4606
4606
}
4607
4607
```
4608
4608
4609
4609
This will print all of the even numbers between one and a hundred.
4610
+ (Note that because ` filter ` doesn't consume the elements that are
4611
+ being iterated over, it is passed a reference to each element, and
4612
+ thus the filter predicate uses the ` &x ` pattern to extract the integer
4613
+ itself.)
4610
4614
4611
4615
You can chain all three things together: start with an iterator, adapt it
4612
4616
a few times, and then consume the result. Check it out:
4613
4617
4614
4618
``` {rust}
4615
4619
range(1i, 1000i)
4616
- .filter(|x| x % 2 == 0)
4617
- .filter(|x| x % 3 == 0)
4620
+ .filter(|& x| x % 2 == 0)
4621
+ .filter(|& x| x % 3 == 0)
4618
4622
.take(5)
4619
4623
.collect::<Vec<int>>();
4620
4624
```
You can’t perform that action at this time.
0 commit comments