orx_concurrent_iter/cloned/
con_iter.rs1use super::chunk_puller::ClonedChunkPuller;
2use crate::{ExactSizeConcurrentIter, concurrent_iter::ConcurrentIter};
3use core::{iter::Cloned, marker::PhantomData};
4
5pub struct ConIterCloned<'a, I, T>
13where
14    T: Clone,
15    I: ConcurrentIter<Item = &'a T>,
16{
17    con_iter: I,
18    phantom: PhantomData<&'a T>,
19}
20
21unsafe impl<'a, I, T> Sync for ConIterCloned<'a, I, T>
22where
23    T: Clone + Send,
24    I: ConcurrentIter<Item = &'a T>,
25{
26}
27
28impl<'a, I, T> ConIterCloned<'a, I, T>
29where
30    T: Clone,
31    I: ConcurrentIter<Item = &'a T>,
32{
33    pub(crate) fn new(con_iter: I) -> Self {
34        Self {
35            con_iter,
36            phantom: PhantomData,
37        }
38    }
39}
40
41impl<'a, I, T> ConcurrentIter for ConIterCloned<'a, I, T>
42where
43    T: Clone + Send,
44    I: ConcurrentIter<Item = &'a T>,
45{
46    type Item = T;
47
48    type SequentialIter = Cloned<I::SequentialIter>;
49
50    type ChunkPuller<'i>
51        = ClonedChunkPuller<'a, T, I::ChunkPuller<'i>>
52    where
53        Self: 'i;
54
55    fn into_seq_iter(self) -> Self::SequentialIter {
56        self.con_iter.into_seq_iter().cloned()
57    }
58
59    fn skip_to_end(&self) {
60        self.con_iter.skip_to_end()
61    }
62
63    fn next(&self) -> Option<Self::Item> {
64        self.con_iter.next().cloned()
65    }
66
67    fn next_with_idx(&self) -> Option<(usize, Self::Item)> {
68        self.con_iter.next_with_idx().map(|(i, x)| (i, x.clone()))
69    }
70
71    fn size_hint(&self) -> (usize, Option<usize>) {
72        self.con_iter.size_hint()
73    }
74
75    fn is_completed_when_none_returned(&self) -> bool {
76        true
77    }
78
79    fn chunk_puller(&self, chunk_size: usize) -> Self::ChunkPuller<'_> {
80        self.con_iter.chunk_puller(chunk_size).into()
81    }
82}
83
84impl<'a, I, T> ExactSizeConcurrentIter for ConIterCloned<'a, I, T>
85where
86    T: Clone + Send,
87    I: ExactSizeConcurrentIter<Item = &'a T>,
88{
89    fn len(&self) -> usize {
90        self.con_iter.len()
91    }
92}