1use std::{fmt, marker::PhantomData};
2
3use crate::iter::{plumbing::*, *};
4
5pub fn empty<T: Send>() -> Empty<T> {
23 Empty {
24 marker: PhantomData,
25 }
26}
27
28pub struct Empty<T: Send> {
30 marker: PhantomData<T>,
31}
32
33impl<T: Send> Clone for Empty<T> {
34 fn clone(&self) -> Self {
35 empty()
36 }
37}
38
39impl<T: Send> fmt::Debug for Empty<T> {
40 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
41 f.pad("Empty")
42 }
43}
44
45impl<T: Send> ParallelIterator for Empty<T> {
46 type Item = T;
47
48 fn drive_unindexed<C>(self, consumer: C) -> C::Result
49 where
50 C: UnindexedConsumer<Self::Item>,
51 {
52 self.drive(consumer)
53 }
54
55 fn opt_len(&self) -> Option<usize> {
56 Some(0)
57 }
58}
59
60impl<T: Send> IndexedParallelIterator for Empty<T> {
61 fn drive<C>(self, consumer: C) -> C::Result
62 where
63 C: Consumer<Self::Item>,
64 {
65 consumer.into_folder().complete()
66 }
67
68 fn len(&self) -> usize {
69 0
70 }
71
72 fn with_producer<CB>(self, callback: CB) -> CB::Output
73 where
74 CB: ProducerCallback<Self::Item>,
75 {
76 callback.callback(EmptyProducer(PhantomData))
77 }
78}
79
80struct EmptyProducer<T: Send>(PhantomData<T>);
82
83impl<T: Send> Producer for EmptyProducer<T> {
84 type IntoIter = std::iter::Empty<T>;
85 type Item = T;
86
87 fn into_iter(self) -> Self::IntoIter {
88 std::iter::empty()
89 }
90
91 fn split_at(self, index: usize) -> (Self, Self) {
92 debug_assert_eq!(index, 0);
93 (self, EmptyProducer(PhantomData))
94 }
95
96 fn fold_with<F>(self, folder: F) -> F
97 where
98 F: Folder<Self::Item>,
99 {
100 folder
101 }
102}