mirror of
https://github.com/rust-lang/book.git
synced 2026-11-30 21:41:18 -06:00
Add lots of hidden code so we test this example
Because I feel like i've messed it up a few times now
This commit is contained in:
@@ -236,7 +236,33 @@ another `Counter` instance after skipping the first value that instance
|
|||||||
produces, multiply each pair together, keep only those results that are
|
produces, multiply each pair together, keep only those results that are
|
||||||
divisible by three, and add all the resulting values together, we could do so:
|
divisible by three, and add all the resulting values together, we could do so:
|
||||||
|
|
||||||
```rust,ignore
|
```rust
|
||||||
|
# struct Counter {
|
||||||
|
# count: u32,
|
||||||
|
# }
|
||||||
|
#
|
||||||
|
# impl Counter {
|
||||||
|
# fn new() -> Counter {
|
||||||
|
# Counter { count: 0 }
|
||||||
|
# }
|
||||||
|
# }
|
||||||
|
#
|
||||||
|
# impl Iterator for Counter {
|
||||||
|
# // Our iterator will produce u32s
|
||||||
|
# type Item = u32;
|
||||||
|
#
|
||||||
|
# fn next(&mut self) -> Option<Self::Item> {
|
||||||
|
# // increment our count. This is why we started at zero.
|
||||||
|
# self.count += 1;
|
||||||
|
#
|
||||||
|
# // check to see if we've finished counting or not.
|
||||||
|
# if self.count < 6 {
|
||||||
|
# Some(self.count)
|
||||||
|
# } else {
|
||||||
|
# None
|
||||||
|
# }
|
||||||
|
# }
|
||||||
|
# }
|
||||||
let sum: u32 = Counter::new().take(5)
|
let sum: u32 = Counter::new().take(5)
|
||||||
.zip(Counter::new().skip(1))
|
.zip(Counter::new().skip(1))
|
||||||
.map(|(a, b)| a * b)
|
.map(|(a, b)| a * b)
|
||||||
|
|||||||
Reference in New Issue
Block a user