Skip to content

Commit 08fc1aa

Browse files
authored
Merge pull request #1425 from Stromberg90/patch-1
Changed impl to use Self::Item
2 parents 717df18 + 8001357 commit 08fc1aa

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

src/trait/iter.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,16 @@ struct Fibonacci {
1818
// Implement `Iterator` for `Fibonacci`.
1919
// The `Iterator` trait only requires a method to be defined for the `next` element.
2020
impl Iterator for Fibonacci {
21+
// We can refer to this type using Self::Item
2122
type Item = u32;
2223
2324
// Here, we define the sequence using `.curr` and `.next`.
2425
// The return type is `Option<T>`:
2526
// * When the `Iterator` is finished, `None` is returned.
2627
// * 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> {
2831
let new_next = self.curr + self.next;
2932
3033
self.curr = self.next;

0 commit comments

Comments
 (0)