1 //! Macros for delegating newtype iterators to inner types.
3 // Note: these place `impl` bounds at the end, as token gobbling is the only way
4 // I know how to consume an arbitrary list of constraints, with `$($args:tt)*`.
6 /// Create a parallel iterator implementation which simply wraps an inner type
7 /// and delegates all methods inward. The actual struct must already be
8 /// declared with an `inner` field.
10 /// The implementation of `IntoParallelIterator` should be added separately.
15 /// delegate_iterator!{
16 /// MyIntoIter<T, U> => (T, U),
17 /// impl<T: Ord + Send, U: Send>
20 macro_rules
! delegate_iterator
{
21 ($iter
:ty
=> $item
:ty
,
24 impl $
( $args
)* ParallelIterator
for $iter
{
27 fn drive_unindexed
<C
>(self, consumer
: C
) -> C
::Result
28 where C
: UnindexedConsumer
<Self::Item
>
30 self.inner
.drive_unindexed(consumer
)
33 fn opt_len(&self) -> Option
<usize> {
40 /// Create an indexed parallel iterator implementation which simply wraps an
41 /// inner type and delegates all methods inward. The actual struct must already
42 /// be declared with an `inner` field.
43 macro_rules
! delegate_indexed_iterator
{
44 ($iter
:ty
=> $item
:ty
,
52 impl $
( $args
)* IndexedParallelIterator
for $iter
{
53 fn drive
<C
>(self, consumer
: C
) -> C
::Result
54 where C
: Consumer
<Self::Item
>
56 self.inner
.drive(consumer
)
59 fn len(&self) -> usize {
63 fn with_producer
<CB
>(self, callback
: CB
) -> CB
::Output
64 where CB
: ProducerCallback
<Self::Item
>
66 self.inner
.with_producer(callback
)