ospf_rust_base/generator_iterator.rs
1use std::ops::{Coroutine, CoroutineState};
2use std::pin::Pin;
3
4pub struct GeneratorIterator<G>(pub G);
5
6impl<G: Coroutine + Unpin> Iterator for GeneratorIterator<G> {
7 type Item = G::Yield;
8
9 fn next(&mut self) -> Option<Self::Item> {
10 match Pin::new(&mut self.0).resume(()) {
11 CoroutineState::Yielded(x) => Some(x),
12 CoroutineState::Complete(_) => None,
13 }
14 }
15}