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/// ```
20#[derive(Debug, Clone, Copy)]
21pub struct ConIterEmpty<T> {
22    phantom: PhantomData<T>,
23}
24
25unsafe impl<T> Sync for ConIterEmpty<T> {}
26
27impl<T> Default for ConIterEmpty<T> {
28    fn default() -> Self {
29        Self::new()
30    }
31}
32
33impl<T> ConIterEmpty<T> {
34    /// Creates a new empty concurrent iterator with no elements.
35    pub fn new() -> Self {
36        Self {
37            phantom: PhantomData,
38        }
39    }
40}
41
42impl<T> ConcurrentIter for ConIterEmpty<T>
43where
44    T: Send,
45{
46    type Item = T;
47
48    type SequentialIter = core::iter::Empty<T>;
49
50    type ChunkPuller<'i>
51        = ChunkPullerEmpty<'i, T>
52    where
53        Self: 'i;
54
55    fn into_seq_iter(self) -> Self::SequentialIter {
56        core::iter::empty()
57    }
58
59    fn skip_to_end(&self) {}
60
61    fn next(&self) -> Option<Self::Item> {
62        None
63    }
64
65    fn next_with_idx(&self) -> Option<(usize, Self::Item)> {
66        None
67    }
68
69    fn size_hint(&self) -> (usize, Option<usize>) {
70        (0, Some(0))
71    }
72
73    fn chunk_puller(&self, chunk_size: usize) -> Self::ChunkPuller<'_> {
74        Self::ChunkPuller::new(self, chunk_size)
75    }
76}
77
78impl<T> ExactSizeConcurrentIter for ConIterEmpty<T>
79where
80    T: Send,
81{
82    fn len(&self) -> usize {
83        0
84    }
85}