rayon/iter/
once.rs
1use crate::iter::plumbing::*;
2use crate::iter::*;
3
4pub fn once<T: Send>(item: T) -> Once<T> {
25 Once { item }
26}
27
28#[derive(Clone, Debug)]
30pub struct Once<T: Send> {
31 item: T,
32}
33
34impl<T: Send> ParallelIterator for Once<T> {
35 type Item = T;
36
37 fn drive_unindexed<C>(self, consumer: C) -> C::Result
38 where
39 C: UnindexedConsumer<Self::Item>,
40 {
41 self.drive(consumer)
42 }
43
44 fn opt_len(&self) -> Option<usize> {
45 Some(1)
46 }
47}
48
49impl<T: Send> IndexedParallelIterator for Once<T> {
50 fn drive<C>(self, consumer: C) -> C::Result
51 where
52 C: Consumer<Self::Item>,
53 {
54 consumer.into_folder().consume(self.item).complete()
55 }
56
57 fn len(&self) -> usize {
58 1
59 }
60
61 fn with_producer<CB>(self, callback: CB) -> CB::Output
62 where
63 CB: ProducerCallback<Self::Item>,
64 {
65 Some(self.item).into_par_iter().with_producer(callback)
67 }
68}