Fibonacci iterator
10 points
Implement Iterator for Fib so that fib() yields the infinite sequence 0, 1, 1, 2, 3, 5, 8, and so on, as u64. Do not collect into a vector; the iterator must produce values one at a time.
Required signature
pub struct Fib { // add the state you need } pub fn fib() -> Fib { todo!() } impl Iterator for Fib { type Item = u64; fn next(&mut self) -> Option<u64> { todo!() } }
Visible tests
-
visible_fib_first_ten#[test] fn visible_fib_first_ten() { let first: Vec<u64> = fib().take(10).collect(); assert_eq!(first, vec![0, 1, 1, 2, 3, 5, 8, 13, 21, 34]); }
Your solution
Log in to submit a solution.