]>
git.proxmox.com Git - rustc.git/blob - src/vendor/rustc-rayon/src/iter/once.rs
4 /// Creates a parallel iterator that produces an element exactly once.
6 /// This admits no parallelism on its own, but it could be chained to existing
7 /// parallel iterators to extend their contents, or otherwise used for any code
8 /// that deals with generic parallel iterators.
13 /// use rayon::prelude::*;
14 /// use rayon::iter::once;
16 /// let pi = (0..1234).into_par_iter()
18 /// .chain(1234..10_000);
20 /// assert_eq!(pi.clone().count(), 10_001);
21 /// assert_eq!(pi.clone().filter(|&x| x < 0).count(), 1);
22 /// assert_eq!(pi.position_any(|x| x < 0), Some(1234));
24 pub fn once
<T
: Send
>(item
: T
) -> Once
<T
> {
28 /// Iterator adaptor for [the `once()` function](fn.once.html).
29 #[derive(Clone, Debug)]
30 pub struct Once
<T
: Send
> {
34 impl<T
: Send
> ParallelIterator
for Once
<T
> {
37 fn drive_unindexed
<C
>(self, consumer
: C
) -> C
::Result
38 where C
: UnindexedConsumer
<Self::Item
>
43 fn opt_len(&self) -> Option
<usize> {
48 impl<T
: Send
> IndexedParallelIterator
for Once
<T
> {
49 fn drive
<C
>(self, consumer
: C
) -> C
::Result
50 where C
: Consumer
<Self::Item
>
52 consumer
.into_folder().consume(self.item
).complete()
55 fn len(&self) -> usize {
59 fn with_producer
<CB
>(self, callback
: CB
) -> CB
::Output
60 where CB
: ProducerCallback
<Self::Item
>
62 // Let `OptionProducer` handle it.
63 Some(self.item
).into_par_iter().with_producer(callback
)