File tree Expand file tree Collapse file tree 1 file changed +4
-1
lines changed Expand file tree Collapse file tree 1 file changed +4
-1
lines changed Original file line number Diff line number Diff line change @@ -18,13 +18,16 @@ struct Fibonacci {
18
18
// Implement `Iterator` for `Fibonacci`.
19
19
// The `Iterator` trait only requires a method to be defined for the `next` element.
20
20
impl Iterator for Fibonacci {
21
+ // We can refer to this type using Self::Item
21
22
type Item = u32;
22
23
23
24
// Here, we define the sequence using `.curr` and `.next`.
24
25
// The return type is `Option<T>`:
25
26
// * When the `Iterator` is finished, `None` is returned.
26
27
// * Otherwise, the next value is wrapped in `Some` and returned.
27
- fn next(&mut self) -> Option<u32> {
28
+ // We use Self::Item in the return type, so we can change
29
+ // the type without having to update the function signatures.
30
+ fn next(&mut self) -> Option<Self::Item> {
28
31
let new_next = self.curr + self.next;
29
32
30
33
self.curr = self.next;
You can’t perform that action at this time.
0 commit comments