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