U2OGZGIQP7X5LIWWK24BJFZDWPLV5YVS7BGG6RZ3GZYUZ75OQK5AC
struct FibIter {
current: usize,
next: usize,
}
impl Default for FibIter {
fn default() -> FibIter {
FibIter {
current: 1,
next: 1,
}
}
}
impl Iterator for FibIter {
type Item = usize;
fn next(&mut self) -> Option<Self::Item> {
let current = self.current;
self.current = self.next;
self.next += current;
Some(current)
}
}
pub fn fib_iter(n: usize) -> Option<usize> {
FibIter::default().nth(n)
}