How implement an iterator over a growing collection?
The Rust Programming Language Forum
How implement an iterator over a growing collection?
AI gives me an example, but unfortunately a collection growing should happen inside the iterator next(). struct GrowingIter { data: Vec<String>, index: usize, } impl Iterator for GrowingIter { type Item = String; fn next(&mut self) -> Option<Self::Item> { if self.index == self.data.len() { return None; } let item = self.data.get(self.index).unwrap().to_string(); self.index += 1; Some(item) } } fn main() { let data =...
0 comments
No comments yet.