1 use super::plumbing
::*;
3 use super::noop
::NoopConsumer
;
6 /// `Skip` is an iterator that skips over the first `n` elements.
7 /// This struct is created by the [`skip()`] method on [`IndexedParallelIterator`]
9 /// [`skip()`]: trait.IndexedParallelIterator.html#method.skip
10 /// [`IndexedParallelIterator`]: trait.IndexedParallelIterator.html
11 #[must_use = "iterator adaptors are lazy and do nothing unless consumed"]
12 #[derive(Debug, Clone)]
18 /// Create a new `Skip` iterator.
20 /// NB: a free fn because it is NOT part of the end-user API.
21 pub fn new
<I
>(base
: I
, n
: usize) -> Skip
<I
>
22 where I
: IndexedParallelIterator
24 let n
= min(base
.len(), n
);
25 Skip { base: base, n: n }
28 impl<I
> ParallelIterator
for Skip
<I
>
29 where I
: IndexedParallelIterator
33 fn drive_unindexed
<C
>(self, consumer
: C
) -> C
::Result
34 where C
: UnindexedConsumer
<Self::Item
>
36 bridge(self, consumer
)
39 fn opt_len(&self) -> Option
<usize> {
44 impl<I
> IndexedParallelIterator
for Skip
<I
>
45 where I
: IndexedParallelIterator
47 fn len(&self) -> usize {
48 self.base
.len() - self.n
51 fn drive
<C
: Consumer
<Self::Item
>>(self, consumer
: C
) -> C
::Result
{
52 bridge(self, consumer
)
55 fn with_producer
<CB
>(self, callback
: CB
) -> CB
::Output
56 where CB
: ProducerCallback
<Self::Item
>
58 return self.base
.with_producer(Callback
{
68 impl<T
, CB
> ProducerCallback
<T
> for Callback
<CB
>
69 where CB
: ProducerCallback
<T
>
71 type Output
= CB
::Output
;
72 fn callback
<P
>(self, base
: P
) -> CB
::Output
73 where P
: Producer
<Item
= T
>
75 let (before_skip
, after_skip
) = base
.split_at(self.n
);
76 bridge_producer_consumer(self.n
, before_skip
, NoopConsumer
::new());
77 self.callback
.callback(after_skip
)