/rust/registry/src/index.crates.io-6f17d22bba15001f/rayon-1.10.0/src/iter/empty.rs
Line | Count | Source (jump to first uncovered line) |
1 | | use crate::iter::plumbing::*; |
2 | | use crate::iter::*; |
3 | | |
4 | | use std::fmt; |
5 | | use std::marker::PhantomData; |
6 | | |
7 | | /// Creates a parallel iterator that produces nothing. |
8 | | /// |
9 | | /// This admits no parallelism on its own, but it could be used for code that |
10 | | /// deals with generic parallel iterators. |
11 | | /// |
12 | | /// # Examples |
13 | | /// |
14 | | /// ``` |
15 | | /// use rayon::prelude::*; |
16 | | /// use rayon::iter::empty; |
17 | | /// |
18 | | /// let pi = (0..1234).into_par_iter() |
19 | | /// .chain(empty()) |
20 | | /// .chain(1234..10_000); |
21 | | /// |
22 | | /// assert_eq!(pi.count(), 10_000); |
23 | | /// ``` |
24 | 0 | pub fn empty<T: Send>() -> Empty<T> { |
25 | 0 | Empty { |
26 | 0 | marker: PhantomData, |
27 | 0 | } |
28 | 0 | } Unexecuted instantiation: rayon::iter::empty::empty::<i8> Unexecuted instantiation: rayon::iter::empty::empty::<u8> Unexecuted instantiation: rayon::iter::empty::empty::<isize> Unexecuted instantiation: rayon::iter::empty::empty::<usize> Unexecuted instantiation: rayon::iter::empty::empty::<i32> Unexecuted instantiation: rayon::iter::empty::empty::<u32> Unexecuted instantiation: rayon::iter::empty::empty::<i128> Unexecuted instantiation: rayon::iter::empty::empty::<u128> Unexecuted instantiation: rayon::iter::empty::empty::<i16> Unexecuted instantiation: rayon::iter::empty::empty::<u16> Unexecuted instantiation: rayon::iter::empty::empty::<i64> Unexecuted instantiation: rayon::iter::empty::empty::<u64> |
29 | | |
30 | | /// Iterator adaptor for [the `empty()` function](fn.empty.html). |
31 | | pub struct Empty<T: Send> { |
32 | | marker: PhantomData<T>, |
33 | | } |
34 | | |
35 | | impl<T: Send> Clone for Empty<T> { |
36 | 0 | fn clone(&self) -> Self { |
37 | 0 | empty() |
38 | 0 | } |
39 | | } |
40 | | |
41 | | impl<T: Send> fmt::Debug for Empty<T> { |
42 | 0 | fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
43 | 0 | f.pad("Empty") |
44 | 0 | } |
45 | | } |
46 | | |
47 | | impl<T: Send> ParallelIterator for Empty<T> { |
48 | | type Item = T; |
49 | | |
50 | 0 | fn drive_unindexed<C>(self, consumer: C) -> C::Result |
51 | 0 | where |
52 | 0 | C: UnindexedConsumer<Self::Item>, |
53 | 0 | { |
54 | 0 | self.drive(consumer) |
55 | 0 | } |
56 | | |
57 | 0 | fn opt_len(&self) -> Option<usize> { |
58 | 0 | Some(0) |
59 | 0 | } Unexecuted instantiation: <rayon::iter::empty::Empty<i8> as rayon::iter::ParallelIterator>::opt_len Unexecuted instantiation: <rayon::iter::empty::Empty<u8> as rayon::iter::ParallelIterator>::opt_len Unexecuted instantiation: <rayon::iter::empty::Empty<isize> as rayon::iter::ParallelIterator>::opt_len Unexecuted instantiation: <rayon::iter::empty::Empty<usize> as rayon::iter::ParallelIterator>::opt_len Unexecuted instantiation: <rayon::iter::empty::Empty<i32> as rayon::iter::ParallelIterator>::opt_len Unexecuted instantiation: <rayon::iter::empty::Empty<u32> as rayon::iter::ParallelIterator>::opt_len Unexecuted instantiation: <rayon::iter::empty::Empty<i128> as rayon::iter::ParallelIterator>::opt_len Unexecuted instantiation: <rayon::iter::empty::Empty<u128> as rayon::iter::ParallelIterator>::opt_len Unexecuted instantiation: <rayon::iter::empty::Empty<i16> as rayon::iter::ParallelIterator>::opt_len Unexecuted instantiation: <rayon::iter::empty::Empty<u16> as rayon::iter::ParallelIterator>::opt_len Unexecuted instantiation: <rayon::iter::empty::Empty<i64> as rayon::iter::ParallelIterator>::opt_len Unexecuted instantiation: <rayon::iter::empty::Empty<u64> as rayon::iter::ParallelIterator>::opt_len |
60 | | } |
61 | | |
62 | | impl<T: Send> IndexedParallelIterator for Empty<T> { |
63 | 0 | fn drive<C>(self, consumer: C) -> C::Result |
64 | 0 | where |
65 | 0 | C: Consumer<Self::Item>, |
66 | 0 | { |
67 | 0 | consumer.into_folder().complete() |
68 | 0 | } |
69 | | |
70 | 0 | fn len(&self) -> usize { |
71 | 0 | 0 |
72 | 0 | } |
73 | | |
74 | 0 | fn with_producer<CB>(self, callback: CB) -> CB::Output |
75 | 0 | where |
76 | 0 | CB: ProducerCallback<Self::Item>, |
77 | 0 | { |
78 | 0 | callback.callback(EmptyProducer(PhantomData)) |
79 | 0 | } |
80 | | } |
81 | | |
82 | | /// Private empty producer |
83 | | struct EmptyProducer<T: Send>(PhantomData<T>); |
84 | | |
85 | | impl<T: Send> Producer for EmptyProducer<T> { |
86 | | type Item = T; |
87 | | type IntoIter = std::iter::Empty<T>; |
88 | | |
89 | 0 | fn into_iter(self) -> Self::IntoIter { |
90 | 0 | std::iter::empty() |
91 | 0 | } |
92 | | |
93 | 0 | fn split_at(self, index: usize) -> (Self, Self) { |
94 | 0 | debug_assert_eq!(index, 0); |
95 | 0 | (self, EmptyProducer(PhantomData)) |
96 | 0 | } |
97 | | |
98 | 0 | fn fold_with<F>(self, folder: F) -> F |
99 | 0 | where |
100 | 0 | F: Folder<Self::Item>, |
101 | 0 | { |
102 | 0 | folder |
103 | 0 | } |
104 | | } |