roopes_core/primitives/emitter/
iterator.rs

1//! Provides a simple wrapper struct around
2//! [`iter::Iterator`].
3use super::Emitter;
4use std::{
5    cell::RefCell,
6    iter,
7};
8
9/// Wraps an [`iter::Iterator`] in an
10/// [`Emitter<Option>`].
11pub struct Iterator<R>
12{
13    iter: RefCell<Box<dyn iter::Iterator<Item = R>>>,
14}
15
16impl<R> Iterator<R>
17{
18    /// Creates a new [`Iterator`] with a given
19    /// [`Box`]ed [`iter::Iterator`].
20    pub fn new(iter: RefCell<Box<dyn iter::Iterator<Item = R>>>)
21        -> Iterator<R>
22    {
23        Iterator { iter }
24    }
25}
26
27impl<R> Emitter<Option<R>> for Iterator<R>
28{
29    fn emit(&self) -> Option<R>
30    {
31        self.iter.borrow_mut().next()
32    }
33}