use crate::*; use super::*; pub enum Collect<'a, E: Engine, const N: usize> { Callback(CallbackCollection<'a, E>), //Iterator(IteratorCollection<'a, E>), Array(ArrayCollection<'a, E, N>), Slice(SliceCollection<'a, E>), } impl<'a, E: Engine, const N: usize> Collect<'a, E, N> { pub fn iter (&'a self) -> CollectIterator<'a, E, N> { CollectIterator(0, &self) } } impl<'a, E: Engine, const N: usize> From> for Collect<'a, E, N> { fn from (callback: CallbackCollection<'a, E>) -> Self { Self::Callback(callback) } } impl<'a, E: Engine, const N: usize> From> for Collect<'a, E, N> { fn from (slice: SliceCollection<'a, E>) -> Self { Self::Slice(slice) } } impl<'a, E: Engine, const N: usize> From> for Collect<'a, E, N>{ fn from (array: ArrayCollection<'a, E, N>) -> Self { Self::Array(array) } } type CallbackCollection<'a, E> = &'a dyn Fn(&'a mut dyn FnMut(&dyn Render)->Usually<()>); //type IteratorCollection<'a, E> = //&'a mut dyn Iterator>; type SliceCollection<'a, E> = &'a [&'a dyn Render]; type ArrayCollection<'a, E, const N: usize> = [&'a dyn Render; N]; pub struct CollectIterator<'a, E: Engine, const N: usize>(usize, &'a Collect<'a, E, N>); impl<'a, E: Engine, const N: usize> Iterator for CollectIterator<'a, E, N> { type Item = &'a dyn Render; fn next (&mut self) -> Option { match self.1 { Collect::Callback(callback) => { todo!() }, //Collection::Iterator(iterator) => { //iterator.next() //}, Collect::Array(array) => { if let Some(item) = array.get(self.0) { self.0 += 1; //Some(item) None } else { None } } Collect::Slice(slice) => { if let Some(item) = slice.get(self.0) { self.0 += 1; //Some(item) None } else { None } } } } }