orx_iterable/obj_safe/transformations/
skipped_while.rs

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