Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- struct Fibonacci {
- current: u64,
- next: u64
- }
- impl Iterator for Fibonacci {
- type Item = u64;
- fn next(&mut self) -> Option<u64> {
- let n = self.current + self.next;
- self.current = self.next;
- self.next = n;
- Some(self.current)
- }
- }
- fn main() {
- let f = Fibonacci {
- current: 1,
- next: 1
- };
- for n in f.take(91) {
- println!("{}", n);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement