Coverage Report

Created: 2026-02-26 07:34

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/rust/registry/src/index.crates.io-1949cf8c6b5b557f/rayon-1.11.0/src/iter/empty.rs
Line
Count
Source
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].
31
///
32
/// [the `empty()` function]: empty()
33
pub struct Empty<T> {
34
    marker: PhantomData<T>,
35
}
36
37
impl<T> Clone for Empty<T> {
38
0
    fn clone(&self) -> Self {
39
0
        Empty {
40
0
            marker: PhantomData,
41
0
        }
42
0
    }
43
}
44
45
impl<T: Send> fmt::Debug for Empty<T> {
46
0
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
47
0
        f.pad("Empty")
48
0
    }
49
}
50
51
impl<T: Send> ParallelIterator for Empty<T> {
52
    type Item = T;
53
54
0
    fn drive_unindexed<C>(self, consumer: C) -> C::Result
55
0
    where
56
0
        C: UnindexedConsumer<Self::Item>,
57
    {
58
0
        self.drive(consumer)
59
0
    }
60
61
0
    fn opt_len(&self) -> Option<usize> {
62
0
        Some(0)
63
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
64
}
65
66
impl<T: Send> IndexedParallelIterator for Empty<T> {
67
0
    fn drive<C>(self, consumer: C) -> C::Result
68
0
    where
69
0
        C: Consumer<Self::Item>,
70
    {
71
0
        consumer.into_folder().complete()
72
0
    }
73
74
0
    fn len(&self) -> usize {
75
0
        0
76
0
    }
77
78
0
    fn with_producer<CB>(self, callback: CB) -> CB::Output
79
0
    where
80
0
        CB: ProducerCallback<Self::Item>,
81
    {
82
0
        callback.callback(EmptyProducer(PhantomData))
83
0
    }
84
}
85
86
/// Private empty producer
87
struct EmptyProducer<T: Send>(PhantomData<T>);
88
89
impl<T: Send> Producer for EmptyProducer<T> {
90
    type Item = T;
91
    type IntoIter = std::iter::Empty<T>;
92
93
0
    fn into_iter(self) -> Self::IntoIter {
94
0
        std::iter::empty()
95
0
    }
96
97
0
    fn split_at(self, index: usize) -> (Self, Self) {
98
0
        debug_assert_eq!(index, 0);
99
0
        (self, EmptyProducer(PhantomData))
100
0
    }
101
102
0
    fn fold_with<F>(self, folder: F) -> F
103
0
    where
104
0
        F: Folder<Self::Item>,
105
    {
106
0
        folder
107
0
    }
108
}