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_windows(42));
105 check(v.par_split(|x| x % 3 == 0));
106 check(v.into_par_iter());
107 }
108
109 #[test]
clone_adaptors()110 fn clone_adaptors() {
111 let v: Vec<_> = (0..1000).map(Some).collect();
112 check(v.par_iter().chain(&v));
113 check(v.par_iter().cloned());
114 check(v.par_iter().copied());
115 check(v.par_iter().enumerate());
116 check(v.par_iter().filter(|_| true));
117 check(v.par_iter().filter_map(|x| *x));
118 check(v.par_iter().flat_map(|x| *x));
119 check(v.par_iter().flatten());
120 check(v.par_iter().with_max_len(1).fold(|| 0, |x, _| x));
121 check(v.par_iter().with_max_len(1).fold_with(0, |x, _| x));
122 check(v.par_iter().with_max_len(1).try_fold(|| 0, |_, &x| x));
123 check(v.par_iter().with_max_len(1).try_fold_with(0, |_, &x| x));
124 check(v.par_iter().inspect(|_| ()));
125 check(v.par_iter().update(|_| ()));
126 check(v.par_iter().interleave(&v));
127 check(v.par_iter().interleave_shortest(&v));
128 check(v.par_iter().intersperse(&None));
129 check(v.par_iter().chunks(3));
130 check(v.par_iter().map(|x| x));
131 check(v.par_iter().map_with(0, |_, x| x));
132 check(v.par_iter().map_init(|| 0, |_, x| x));
133 check(v.par_iter().panic_fuse());
134 check(v.par_iter().rev());
135 check(v.par_iter().skip(1));
136 check(v.par_iter().take(1));
137 check(v.par_iter().cloned().while_some());
138 check(v.par_iter().with_max_len(1));
139 check(v.par_iter().with_min_len(1));
140 check(v.par_iter().zip(&v));
141 check(v.par_iter().zip_eq(&v));
142 }
143
144 #[test]
clone_empty()145 fn clone_empty() {
146 check(rayon::iter::empty::<i32>());
147 }
148
149 #[test]
clone_once()150 fn clone_once() {
151 check(rayon::iter::once(10));
152 }
153
154 #[test]
clone_repeat()155 fn clone_repeat() {
156 let x: Option<i32> = None;
157 check(rayon::iter::repeat(x).while_some());
158 check(rayon::iter::repeatn(x, 1000));
159 }
160
161 #[test]
clone_splitter()162 fn clone_splitter() {
163 check(rayon::iter::split(0..1000, |x| (x, None)));
164 }
165
166 #[test]
clone_multizip()167 fn clone_multizip() {
168 let v: &Vec<_> = &(0..1000).collect();
169 check((v,).into_par_iter());
170 check((v, v).into_par_iter());
171 check((v, v, v).into_par_iter());
172 check((v, v, v, v).into_par_iter());
173 check((v, v, v, v, v).into_par_iter());
174 check((v, v, v, v, v, v).into_par_iter());
175 check((v, v, v, v, v, v, v).into_par_iter());
176 check((v, v, v, v, v, v, v, v).into_par_iter());
177 check((v, v, v, v, v, v, v, v, v).into_par_iter());
178 check((v, v, v, v, v, v, v, v, v, v).into_par_iter());
179 check((v, v, v, v, v, v, v, v, v, v, v).into_par_iter());
180 check((v, v, v, v, v, v, v, v, v, v, v, v).into_par_iter());
181 }
182