1 use rayon::prelude::*;
2
check<I>(iter: I) where I: ParallelIterator + Clone, I::Item: std::fmt::Debug + PartialEq,3 fn check<I>(iter: I)
4 where
5 I: ParallelIterator + Clone,
6 I::Item: std::fmt::Debug + PartialEq,
7 {
8 let a: Vec<_> = iter.clone().collect();
9 let b: Vec<_> = iter.collect();
10 assert_eq!(a, b);
11 }
12
13 #[test]
clone_binary_heap()14 fn clone_binary_heap() {
15 use std::collections::BinaryHeap;
16 let heap: BinaryHeap<_> = (0..1000).collect();
17 check(heap.par_iter());
18 check(heap.into_par_iter());
19 }
20
21 #[test]
clone_btree_map()22 fn clone_btree_map() {
23 use std::collections::BTreeMap;
24 let map: BTreeMap<_, _> = (0..1000).enumerate().collect();
25 check(map.par_iter());
26 }
27
28 #[test]
clone_btree_set()29 fn clone_btree_set() {
30 use std::collections::BTreeSet;
31 let set: BTreeSet<_> = (0..1000).collect();
32 check(set.par_iter());
33 }
34
35 #[test]
clone_hash_map()36 fn clone_hash_map() {
37 use std::collections::HashMap;
38 let map: HashMap<_, _> = (0..1000).enumerate().collect();
39 check(map.par_iter());
40 }
41
42 #[test]
clone_hash_set()43 fn clone_hash_set() {
44 use std::collections::HashSet;
45 let set: HashSet<_> = (0..1000).collect();
46 check(set.par_iter());
47 }
48
49 #[test]
clone_linked_list()50 fn clone_linked_list() {
51 use std::collections::LinkedList;
52 let list: LinkedList<_> = (0..1000).collect();
53 check(list.par_iter());
54 check(list.into_par_iter());
55 }
56
57 #[test]
clone_vec_deque()58 fn clone_vec_deque() {
59 use std::collections::VecDeque;
60 let deque: VecDeque<_> = (0..1000).collect();
61 check(deque.par_iter());
62 check(deque.into_par_iter());
63 }
64
65 #[test]
clone_option()66 fn clone_option() {
67 let option = Some(0);
68 check(option.par_iter());
69 check(option.into_par_iter());
70 }
71
72 #[test]
clone_result()73 fn clone_result() {
74 let result = Ok::<_, ()>(0);
75 check(result.par_iter());
76 check(result.into_par_iter());
77 }
78
79 #[test]
clone_range()80 fn clone_range() {
81 check((0..1000).into_par_iter());
82 }
83
84 #[test]
clone_range_inclusive()85 fn clone_range_inclusive() {
86 check((0..=1000).into_par_iter());
87 }
88
89 #[test]
clone_str()90 fn clone_str() {
91 let s = include_str!("clones.rs");
92 check(s.par_chars());
93 check(s.par_lines());
94 check(s.par_split('\n'));
95 check(s.par_split_terminator('\n'));
96 check(s.par_split_whitespace());
97 }
98
99 #[test]
clone_vec()100 fn clone_vec() {
101 let v: Vec<_> = (0..1000).collect();
102 check(v.par_iter());
103 check(v.par_chunks(42));
104 check(v.par_chunks_exact(42));
105 check(v.par_windows(42));
106 check(v.par_split(|x| x % 3 == 0));
107 check(v.into_par_iter());
108 }
109
110 #[test]
clone_adaptors()111 fn clone_adaptors() {
112 let v: Vec<_> = (0..1000).map(Some).collect();
113 check(v.par_iter().chain(&v));
114 check(v.par_iter().cloned());
115 check(v.par_iter().copied());
116 check(v.par_iter().enumerate());
117 check(v.par_iter().filter(|_| true));
118 check(v.par_iter().filter_map(|x| *x));
119 check(v.par_iter().flat_map(|x| *x));
120 check(v.par_iter().flat_map_iter(|x| *x));
121 check(v.par_iter().flatten());
122 check(v.par_iter().flatten_iter());
123 check(v.par_iter().with_max_len(1).fold(|| 0, |x, _| x));
124 check(v.par_iter().with_max_len(1).fold_with(0, |x, _| x));
125 check(v.par_iter().with_max_len(1).try_fold(|| 0, |_, &x| x));
126 check(v.par_iter().with_max_len(1).try_fold_with(0, |_, &x| x));
127 check(v.par_iter().inspect(|_| ()));
128 check(v.par_iter().update(|_| ()));
129 check(v.par_iter().interleave(&v));
130 check(v.par_iter().interleave_shortest(&v));
131 check(v.par_iter().intersperse(&None));
132 check(v.par_iter().chunks(3));
133 check(v.par_iter().map(|x| x));
134 check(v.par_iter().map_with(0, |_, x| x));
135 check(v.par_iter().map_init(|| 0, |_, x| x));
136 check(v.par_iter().panic_fuse());
137 check(v.par_iter().positions(|_| true));
138 check(v.par_iter().rev());
139 check(v.par_iter().skip(1));
140 check(v.par_iter().take(1));
141 check(v.par_iter().cloned().while_some());
142 check(v.par_iter().with_max_len(1));
143 check(v.par_iter().with_min_len(1));
144 check(v.par_iter().zip(&v));
145 check(v.par_iter().zip_eq(&v));
146 check(v.par_iter().step_by(2));
147 }
148
149 #[test]
clone_empty()150 fn clone_empty() {
151 check(rayon::iter::empty::<i32>());
152 }
153
154 #[test]
clone_once()155 fn clone_once() {
156 check(rayon::iter::once(10));
157 }
158
159 #[test]
clone_repeat()160 fn clone_repeat() {
161 let x: Option<i32> = None;
162 check(rayon::iter::repeat(x).while_some());
163 check(rayon::iter::repeatn(x, 1000));
164 }
165
166 #[test]
clone_splitter()167 fn clone_splitter() {
168 check(rayon::iter::split(0..1000, |x| (x, None)));
169 }
170
171 #[test]
clone_multizip()172 fn clone_multizip() {
173 let v: &Vec<_> = &(0..1000).collect();
174 check((v,).into_par_iter());
175 check((v, v).into_par_iter());
176 check((v, v, v).into_par_iter());
177 check((v, v, v, v).into_par_iter());
178 check((v, v, v, v, v).into_par_iter());
179 check((v, v, v, v, v, v).into_par_iter());
180 check((v, v, v, v, v, v, v).into_par_iter());
181 check((v, v, v, v, v, v, v, v).into_par_iter());
182 check((v, v, v, v, v, v, v, v, v).into_par_iter());
183 check((v, v, v, v, v, v, v, v, v, v).into_par_iter());
184 check((v, v, v, v, v, v, v, v, v, v, v).into_par_iter());
185 check((v, v, v, v, v, v, v, v, v, v, v, v).into_par_iter());
186 }
187