orx_concurrent_iter/
next.rs

1/// Result of a `next_id_and_value` call on a concurrent iterator which contains two bits of information:
2/// * `idx`: index of the element in the iterator.
3/// * `value`: of the element.
4#[derive(Debug)]
5pub struct Next<T> {
6    /// Index of the element in the iterator.
7    pub idx: usize,
8    /// Value of the element.
9    pub value: T,
10}
11
12impl<T: Clone> Next<&T> {
13    /// Converts the next into one where the `value` is cloned.
14    pub fn cloned(self) -> Next<T> {
15        Next {
16            idx: self.idx,
17            value: self.value.clone(),
18        }
19    }
20}
21
22impl<T: Copy> Next<&T> {
23    /// Converts the next into one where the `value` is copied.
24    pub fn copied(self) -> Next<T> {
25        Next {
26            idx: self.idx,
27            value: *self.value,
28        }
29    }
30}
31
32/// A trait representing return types of a `next_chunk` call on a concurrent iterator.
33pub struct NextChunk<T, Iter>
34where
35    Iter: ExactSizeIterator<Item = T>,
36{
37    /// The index of the first element to be yielded by the `values` iterator.
38    pub begin_idx: usize,
39
40    /// Elements in the obtained chunk.
41    pub values: Iter,
42}
43
44impl<'a, T: Clone, Iter> NextChunk<&'a T, Iter>
45where
46    Iter: ExactSizeIterator<Item = &'a T>,
47{
48    /// Converts the next into one where the `values` are cloned.
49    pub fn cloned(self) -> NextChunk<T, core::iter::Cloned<Iter>> {
50        NextChunk {
51            begin_idx: self.begin_idx,
52            values: self.values.cloned(),
53        }
54    }
55}
56
57impl<'a, T: Copy, Iter> NextChunk<&'a T, Iter>
58where
59    Iter: ExactSizeIterator<Item = &'a T>,
60{
61    /// Converts the next into one where the `values` are copied.
62    pub fn copied(self) -> NextChunk<T, core::iter::Copied<Iter>> {
63        NextChunk {
64            begin_idx: self.begin_idx,
65            values: self.values.copied(),
66        }
67    }
68}