]> git.proxmox.com Git - rustc.git/blob - src/vendor/rustc-rayon/src/delegate.rs
New upstream version 1.28.0~beta.14+dfsg1
[rustc.git] / src / vendor / rustc-rayon / src / delegate.rs
1 //! Macros for delegating newtype iterators to inner types.
2
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)*`.
5
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.
9 ///
10 /// The implementation of `IntoParallelIterator` should be added separately.
11 ///
12 /// # Example
13 ///
14 /// ```
15 /// delegate_iterator!{
16 /// MyIntoIter<T, U> => (T, U),
17 /// impl<T: Ord + Send, U: Send>
18 /// }
19 /// ```
20 macro_rules! delegate_iterator {
21 ($iter:ty => $item:ty ,
22 impl $( $args:tt )*
23 ) => {
24 impl $( $args )* ParallelIterator for $iter {
25 type Item = $item;
26
27 fn drive_unindexed<C>(self, consumer: C) -> C::Result
28 where C: UnindexedConsumer<Self::Item>
29 {
30 self.inner.drive_unindexed(consumer)
31 }
32
33 fn opt_len(&self) -> Option<usize> {
34 self.inner.opt_len()
35 }
36 }
37 }
38 }
39
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 ,
45 impl $( $args:tt )*
46 ) => {
47 delegate_iterator!{
48 $iter => $item ,
49 impl $( $args )*
50 }
51
52 impl $( $args )* IndexedParallelIterator for $iter {
53 fn drive<C>(self, consumer: C) -> C::Result
54 where C: Consumer<Self::Item>
55 {
56 self.inner.drive(consumer)
57 }
58
59 fn len(&self) -> usize {
60 self.inner.len()
61 }
62
63 fn with_producer<CB>(self, callback: CB) -> CB::Output
64 where CB: ProducerCallback<Self::Item>
65 {
66 self.inner.with_producer(callback)
67 }
68 }
69 }
70 }