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