|
8 | 8 | /// declared with an `inner` field.
|
9 | 9 | ///
|
10 | 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 | 11 | macro_rules! delegate_iterator {
|
21 | 12 | ($iter:ty => $item:ty ,
|
22 | 13 | impl $( $args:tt )*
|
@@ -68,3 +59,51 @@ macro_rules! delegate_indexed_iterator {
|
68 | 59 | }
|
69 | 60 | }
|
70 | 61 | }
|
| 62 | + |
| 63 | +#[test] |
| 64 | +fn unindexed_example() { |
| 65 | + use crate::collections::btree_map::IntoIter; |
| 66 | + use crate::iter::plumbing::*; |
| 67 | + use crate::prelude::*; |
| 68 | + |
| 69 | + use std::collections::BTreeMap; |
| 70 | + |
| 71 | + struct MyIntoIter<T: Ord + Send, U: Send> { |
| 72 | + inner: IntoIter<T, U>, |
| 73 | + } |
| 74 | + |
| 75 | + delegate_iterator! { |
| 76 | + MyIntoIter<T, U> => (T, U), |
| 77 | + impl<T: Ord + Send, U: Send> |
| 78 | + } |
| 79 | + |
| 80 | + let map = BTreeMap::from([(1, 'a'), (2, 'b'), (3, 'c')]); |
| 81 | + let iter = MyIntoIter { |
| 82 | + inner: map.into_par_iter(), |
| 83 | + }; |
| 84 | + let vec: Vec<_> = iter.map(|(k, _)| k).collect(); |
| 85 | + assert_eq!(vec, &[1, 2, 3]); |
| 86 | +} |
| 87 | + |
| 88 | +#[test] |
| 89 | +fn indexed_example() { |
| 90 | + use crate::iter::plumbing::*; |
| 91 | + use crate::prelude::*; |
| 92 | + use crate::vec::IntoIter; |
| 93 | + |
| 94 | + struct MyIntoIter<T: Send> { |
| 95 | + inner: IntoIter<T>, |
| 96 | + } |
| 97 | + |
| 98 | + delegate_indexed_iterator! { |
| 99 | + MyIntoIter<T> => T, |
| 100 | + impl<T: Send> |
| 101 | + } |
| 102 | + |
| 103 | + let iter = MyIntoIter { |
| 104 | + inner: vec![1, 2, 3].into_par_iter(), |
| 105 | + }; |
| 106 | + let mut vec = vec![]; |
| 107 | + iter.collect_into_vec(&mut vec); |
| 108 | + assert_eq!(vec, &[1, 2, 3]); |
| 109 | +} |
0 commit comments