Datasets:

Modalities:
Text
Formats:
text
Size:
< 1K
Libraries:
Datasets
License:
PyRs2 / rust /src /iterators.rs
khulnasoft's picture
Upload folder using huggingface_hub
998b6cc verified
raw
history blame contribute delete
518 Bytes
struct Fibonacci {
limit: u32,
a: u32,
b: u32,
}
impl Fibonacci {
fn new(limit: u32) -> Self {
Fibonacci { limit, a: 0, b: 1 }
}
}
impl Iterator for Fibonacci {
type Item = u32;
fn next(&mut self) -> Option<Self::Item> {
if self.a > self.limit {
return None;
}
let val = self.a;
self.a = self.b;
self.b = val + self.b;
Some(val)
}
}
fn main() {
for i in Fibonacci::new(100) {
println!("{}", i);
}
}