general-iter 0.1.0

An enum of iterators to avoid Box<&dyn Iterator>
Documentation

use std::iter::FusedIterator;

use GeneralIterator::*;

#[derive(Debug, Clone, Copy, Hash, PartialEq, Eq, PartialOrd, Ord)]
pub enum GeneralIterator<A, B, C = A, D = A, E = A, F = A, G = A, H = A, I = A, J = A> {
    IA(A),
    IB(B),
    IC(C),
    ID(D),
    IE(E),
    IF(F),
    IG(G),
    IH(H),
    II(I),
    IJ(J),
}

impl<A, B, C, D, E, F, G, H, I, J, T> Iterator for GeneralIterator<A, B, C, D, E, F, G, H, I, J>
where
    A: Iterator<Item = T>,
    B: Iterator<Item = T>,
    C: Iterator<Item = T>,
    D: Iterator<Item = T>,
    E: Iterator<Item = T>,
    F: Iterator<Item = T>,
    G: Iterator<Item = T>,
    H: Iterator<Item = T>,
    I: Iterator<Item = T>,
    J: Iterator<Item = T>,
{
    type Item = T;
    
    #[inline(always)]
    fn next(&mut self) -> Option<Self::Item> {
        match self {
            IA(i) => i.next(),
            IB(i) => i.next(),
            IC(i) => i.next(),
            ID(i) => i.next(),
            IE(i) => i.next(),
            IF(i) => i.next(),
            IG(i) => i.next(),
            IH(i) => i.next(),
            II(i) => i.next(),
            IJ(i) => i.next(),
        }
    }
}

impl<A, B, C, D, E, F, G, H, I, J, T> ExactSizeIterator for GeneralIterator<A, B, C, D, E, F, G, H, I, J>
where
    Self: Iterator<Item = T>,
    A: ExactSizeIterator,
    B: ExactSizeIterator,
    C: ExactSizeIterator,
    D: ExactSizeIterator,
    E: ExactSizeIterator,
    F: ExactSizeIterator,
    G: ExactSizeIterator,
    H: ExactSizeIterator,
    I: ExactSizeIterator,
    J: ExactSizeIterator,
{
    #[inline(always)]
    fn len(&self) -> usize {
        match self {
            IA(i) => i.len(),
            IB(i) => i.len(),
            IC(i) => i.len(),
            ID(i) => i.len(),
            IE(i) => i.len(),
            IF(i) => i.len(),
            IG(i) => i.len(),
            IH(i) => i.len(),
            II(i) => i.len(),
            IJ(i) => i.len(),
        }
    }
}

impl<A, B, C, D, E, F, G, H, I, J, T> FusedIterator for GeneralIterator<A, B, C, D, E, F, G, H, I, J>
where
    Self: Iterator<Item = T>,
    A: FusedIterator,
    B: FusedIterator,
    C: FusedIterator,
    D: FusedIterator,
    E: FusedIterator,
    F: FusedIterator,
    G: FusedIterator,
    H: FusedIterator,
    I: FusedIterator,
    J: FusedIterator,
{}

impl<A, B, C, D, E, F, G, H, I, J, T> DoubleEndedIterator for GeneralIterator<A, B, C, D, E, F, G, H, I, J>
where
    Self: Iterator<Item = T>,
    A: DoubleEndedIterator<Item = T>,
    B: DoubleEndedIterator<Item = T>,
    C: DoubleEndedIterator<Item = T>,
    D: DoubleEndedIterator<Item = T>,
    E: DoubleEndedIterator<Item = T>,
    F: DoubleEndedIterator<Item = T>,
    G: DoubleEndedIterator<Item = T>,
    H: DoubleEndedIterator<Item = T>,
    I: DoubleEndedIterator<Item = T>,
    J: DoubleEndedIterator<Item = T>,
{
    #[inline(always)]
    fn next_back(&mut self) -> Option<Self::Item> {
        match self {
            IA(i) => i.next_back(),
            IB(i) => i.next_back(),
            IC(i) => i.next_back(),
            ID(i) => i.next_back(),
            IE(i) => i.next_back(),
            IF(i) => i.next_back(),
            IG(i) => i.next_back(),
            IH(i) => i.next_back(),
            II(i) => i.next_back(),
            IJ(i) => i.next_back(),
        }
    }
}

pub trait IntoGeneralIterator {
    #[inline(always)]
    fn type1<B, C, D, E, F, G, H, I, J>(self) -> GeneralIterator<Self, B, C, D, E, F, G, H, I, J> where Self: Sized {
        IA(self)
    }
    
    #[inline(always)]
    fn type2<A, C, D, E, F, G, H, I, J>(self) -> GeneralIterator<A, Self, C, D, E, F, G, H, I, J> where Self: Sized {
        IB(self)
    }
    
    #[inline(always)]
    fn type3<A, B, D, E, F, G, H, I, J>(self) -> GeneralIterator<A, B, Self, D, E, F, G, H, I, J> where Self: Sized {
        IC(self)
    }
    
    #[inline(always)]
    fn type4<A, B, C, E, F, G, H, I, J>(self) -> GeneralIterator<A, B, C, Self, E, F, G, H, I, J> where Self: Sized {
        ID(self)
    }
    
    #[inline(always)]
    fn type5<A, B, C, D, F, G, H, I, J>(self) -> GeneralIterator<A, B, C, D, Self, F, G, H, I, J> where Self: Sized {
        IE(self)
    }
    
    #[inline(always)]
    fn type6<A, B, C, D, E, G, H, I, J>(self) -> GeneralIterator<A, B, C, D, E, Self, G, H, I, J> where Self: Sized {
        IF(self)
    }
    
    #[inline(always)]
    fn type7<A, B, C, D, E, F, H, I, J>(self) -> GeneralIterator<A, B, C, D, E, F, Self, H, I, J> where Self: Sized {
        IG(self)
    }
    
    #[inline(always)]
    fn type8<A, B, C, D, E, F, G, I, J>(self) -> GeneralIterator<A, B, C, D, E, F, G, Self, I, J> where Self: Sized {
        IH(self)
    }
    
    #[inline(always)]
    fn type9<A, B, C, D, E, F, G, H, J>(self) -> GeneralIterator<A, B, C, D, E, F, G, H, Self, J> where Self: Sized {
        II(self)
    }
    
    #[inline(always)]
    fn type10<A, B, C, D, E, F, G, H, I>(self) -> GeneralIterator<A, B, C, D, E, F, G, H, I, Self> where Self: Sized {
        IJ(self)
    }
}

impl<T: Iterator> IntoGeneralIterator for T {}