orx_concurrent_iter/cloned/
chunk_puller.rs

1use crate::pullers::ChunkPuller;
2use core::iter::Cloned;
3
4/// Chunk puller of a cloned concurrent iterator; i.e., [`ConIterCloned`]
5///
6/// [`ConIterCloned`]: crate::cloned::ConIterCloned
7pub struct ClonedChunkPuller<'i, T, P>
8where
9    T: Clone + 'i,
10    P: ChunkPuller<ChunkItem = &'i T>,
11{
12    puller: P,
13}
14
15impl<'i, T, P> From<P> for ClonedChunkPuller<'i, T, P>
16where
17    T: Clone + 'i,
18    P: ChunkPuller<ChunkItem = &'i T>,
19{
20    fn from(puller: P) -> Self {
21        Self { puller }
22    }
23}
24
25impl<'i, T, P> ChunkPuller for ClonedChunkPuller<'i, T, P>
26where
27    T: Clone + 'i,
28    P: ChunkPuller<ChunkItem = &'i T>,
29{
30    type ChunkItem = T;
31
32    type Chunk<'c>
33        = Cloned<P::Chunk<'c>>
34    where
35        Self: 'c;
36
37    fn chunk_size(&self) -> usize {
38        self.puller.chunk_size()
39    }
40
41    fn pull(&mut self) -> Option<Self::Chunk<'_>> {
42        self.puller.pull().map(|x| x.cloned())
43    }
44
45    fn pull_with_idx(&mut self) -> Option<(usize, Self::Chunk<'_>)> {
46        self.puller
47            .pull_with_idx()
48            .map(|(begin_idx, x)| (begin_idx, x.cloned()))
49    }
50}