orx_concurrent_iter/implementations/empty/
con_iter.rs

1use super::chunk_puller::ChunkPullerEmpty;
2use crate::{ConcurrentIter, exact_size_concurrent_iter::ExactSizeConcurrentIter};
3use core::marker::PhantomData;
4
5/// An empty concurrent iterator which does not yield any elements.
6///
7/// # Examples
8///
9/// ```
10/// use orx_concurrent_iter::*;
11///
12/// let con_iter = iter::empty::<String>();
13/// assert_eq!(con_iter.next(), None);
14///
15/// // or
16///
17/// let con_iter = implementations::ConIterEmpty::<String>::new();
18/// assert_eq!(con_iter.next(), None);
19/// ```
20pub struct ConIterEmpty<T: Send + Sync> {
21    phantom: PhantomData<T>,
22}
23
24unsafe impl<T: Send + Sync> Sync for ConIterEmpty<T> {}
25
26unsafe impl<T: Send + Sync> Send for ConIterEmpty<T> {}
27
28impl<T> Default for ConIterEmpty<T>
29where
30    T: Send + Sync,
31{
32    fn default() -> Self {
33        Self::new()
34    }
35}
36
37impl<T> ConIterEmpty<T>
38where
39    T: Send + Sync,
40{
41    /// Creates a new empty concurrent iterator with no elements.
42    pub fn new() -> Self {
43        Self {
44            phantom: PhantomData,
45        }
46    }
47}
48
49impl<T> ConcurrentIter for ConIterEmpty<T>
50where
51    T: Send + Sync,
52{
53    type Item = T;
54
55    type SequentialIter = core::iter::Empty<T>;
56
57    type ChunkPuller<'i>
58        = ChunkPullerEmpty<'i, T>
59    where
60        Self: 'i;
61
62    fn into_seq_iter(self) -> Self::SequentialIter {
63        core::iter::empty()
64    }
65
66    fn skip_to_end(&self) {}
67
68    fn next(&self) -> Option<Self::Item> {
69        None
70    }
71
72    fn next_with_idx(&self) -> Option<(usize, Self::Item)> {
73        None
74    }
75
76    fn size_hint(&self) -> (usize, Option<usize>) {
77        (0, Some(0))
78    }
79
80    fn chunk_puller(&self, chunk_size: usize) -> Self::ChunkPuller<'_> {
81        Self::ChunkPuller::new(self, chunk_size)
82    }
83}
84
85impl<T> ExactSizeConcurrentIter for ConIterEmpty<T>
86where
87    T: Send + Sync,
88{
89    fn len(&self) -> usize {
90        0
91    }
92}