1use std::marker::PhantomData;
2
3use crate::{Quad, Triple};
4
5pub struct InfallibleIterator<I>(pub I);
6
7impl<I: Iterator> Iterator for InfallibleIterator<I> {
8 type Item = Result<I::Item, std::convert::Infallible>;
9
10 fn next(&mut self) -> Option<Self::Item> {
11 self.0.next().map(Ok)
12 }
13}
14
15pub struct TripleToQuadIterator<I, G>(I, PhantomData<G>);
16
17impl<I, G> TripleToQuadIterator<I, G> {
18 pub fn new(inner: I) -> Self {
19 Self(inner, PhantomData)
20 }
21}
22
23impl<S, P, O, G, I: Iterator<Item = Triple<S, P, O>>> Iterator for TripleToQuadIterator<I, G> {
24 type Item = Quad<S, P, O, G>;
25
26 fn next(&mut self) -> Option<Self::Item> {
27 self.0.next().map(|t| t.into_quad(None))
28 }
29}
30
31pub struct OptionIterator<I>(pub Option<I>);
32
33impl<I: Iterator> Iterator for OptionIterator<I> {
34 type Item = I::Item;
35
36 fn next(&mut self) -> Option<Self::Item> {
37 self.0.as_mut().and_then(I::next)
38 }
39}