orx_iterable/obj_safe/transformations/
chained.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
use crate::{
    obj_safe::{CollectionMutObj, CollectionObj, IterableObj},
    transformations::{Chained, ChainedCol},
    Collection, CollectionMut, Iterable,
};
use orx_self_or::SoM;
use std::boxed::Box;

impl<I1, I2> IterableObj for Chained<I1, I2>
where
    I1: Iterable,
    I2: Iterable<Item = I1::Item>,
{
    type Item = I1::Item;

    fn boxed_iter(&self) -> Box<dyn Iterator<Item = Self::Item> + '_> {
        Box::new(self.it1.iter().chain(self.it2.iter()))
    }
}

// col

impl<'a, I1, I2, E1, E2> IterableObj for &'a ChainedCol<I1, I2, E1, E2>
where
    I1: Collection,
    I2: Collection<Item = <I1 as Collection>::Item>,
    E1: SoM<I1>,
    E2: SoM<I2>,
{
    type Item = &'a <I1 as Collection>::Item;

    fn boxed_iter(&self) -> Box<dyn Iterator<Item = Self::Item> + '_> {
        Box::new(self.it1.get_ref().iter().chain(self.it2.get_ref().iter()))
    }
}

impl<I1, I2, E1, E2> CollectionObj for ChainedCol<I1, I2, E1, E2>
where
    I1: Collection,
    I2: Collection<Item = <I1 as Collection>::Item>,
    E1: SoM<I1>,
    E2: SoM<I2>,
{
    type Item = <I1 as Collection>::Item;

    fn boxed_iter(&self) -> Box<dyn Iterator<Item = &Self::Item> + '_> {
        Box::new(self.iter())
    }
}

impl<I1, I2, E1, E2> CollectionMutObj for ChainedCol<I1, I2, E1, E2>
where
    I1: CollectionMut,
    I2: CollectionMut<Item = <I1 as Collection>::Item>,
    E1: SoM<I1>,
    E2: SoM<I2>,
{
    fn boxed_iter_mut(&mut self) -> Box<dyn Iterator<Item = &mut Self::Item> + '_> {
        Box::new(
            self.it1
                .get_mut()
                .iter_mut()
                .chain(self.it2.get_mut().iter_mut()),
        )
    }
}