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