orx_iterable/obj_safe/transformations/
flattened.rs

1use orx_self_or::SoM;
2
3use crate::{
4    obj_safe::{CollectionMutObj, CollectionObj, IterableObj},
5    transformations::{Flattened, FlattenedCol},
6    Collection, CollectionMut, Iterable,
7};
8use std::boxed::Box;
9
10impl<I> IterableObj for Flattened<I>
11where
12    I: Iterable,
13    I::Item: IntoIterator,
14{
15    type Item = <I::Item as IntoIterator>::Item;
16
17    fn boxed_iter(&self) -> Box<dyn Iterator<Item = Self::Item> + '_> {
18        Box::new(self.it.iter().flatten())
19    }
20}
21
22// col
23
24impl<'a, I, E> IterableObj for &'a FlattenedCol<I, E>
25where
26    I: Collection,
27    I::Item: IntoIterator,
28    for<'i> &'i I::Item: IntoIterator<Item = &'i <I::Item as IntoIterator>::Item>,
29    E: SoM<I>,
30{
31    type Item = &'a <I::Item as IntoIterator>::Item;
32
33    fn boxed_iter(&self) -> Box<dyn Iterator<Item = Self::Item> + '_> {
34        Box::new(self.it.get_ref().iter().flatten())
35    }
36}
37
38impl<I, E> CollectionObj for FlattenedCol<I, E>
39where
40    I: Collection,
41    I::Item: IntoIterator,
42    for<'i> &'i I::Item: IntoIterator<Item = &'i <I::Item as IntoIterator>::Item>,
43    E: SoM<I>,
44{
45    type Item = <I::Item as IntoIterator>::Item;
46
47    fn boxed_iter(&self) -> Box<dyn Iterator<Item = &Self::Item> + '_> {
48        Box::new(self.iter())
49    }
50}
51
52impl<I, E> CollectionMutObj for FlattenedCol<I, E>
53where
54    I: CollectionMut,
55    I::Item: IntoIterator,
56    for<'i> &'i I::Item: IntoIterator<Item = &'i <I::Item as IntoIterator>::Item>,
57    for<'i> &'i mut I::Item: IntoIterator<Item = &'i mut <I::Item as IntoIterator>::Item>,
58    E: SoM<I>,
59{
60    fn boxed_iter_mut(&mut self) -> Box<dyn Iterator<Item = &mut Self::Item> + '_> {
61        Box::new(self.it.get_mut().iter_mut().flatten())
62    }
63}