Created
January 10, 2016 03:42
-
-
Save ivan/9fa904da8857509c2811 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extern crate num; | |
use num::{BigUint, Zero, One}; | |
use std::mem::replace; | |
struct Fib { | |
f1: BigUint, | |
f2: BigUint | |
} | |
impl Iterator for Fib { | |
type Item = BigUint; | |
fn next(&mut self) -> Option<BigUint> { | |
let f0 = replace(&mut self.f1, self.f2.clone()); | |
self.f2 = f0 + &self.f1; | |
return Some(self.f2.clone()); | |
} | |
} | |
fn main() { | |
let f = Fib { | |
f1: BigUint::zero(), | |
f2: BigUint::one() | |
}; | |
for n in f { | |
println!("{}", n); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Without the first
self.f2.clone()
: