mirror of
https://github.com/LukasKalbertodt/programmieren-in-rust.git
synced 2024-11-18 10:58:57 +01:00
32 lines
461 B
Rust
Executable File
32 lines
461 B
Rust
Executable File
struct Fib {
|
|
curr: u64,
|
|
last: u64,
|
|
}
|
|
|
|
impl Fib {
|
|
fn new() -> Self {
|
|
Fib {
|
|
curr: 1,
|
|
last: 0,
|
|
}
|
|
}
|
|
}
|
|
|
|
impl Iterator for Fib {
|
|
type Item = u64;
|
|
fn next(&mut self) -> Option<Self::Item> {
|
|
let new = self.last + self.curr;
|
|
self.last = self.curr;
|
|
self.curr = new;
|
|
|
|
Some(self.last)
|
|
}
|
|
}
|
|
|
|
|
|
fn main() {
|
|
for i in Fib::new().take(20) {
|
|
println!("{}", i);
|
|
}
|
|
}
|