1 use rayon::prelude::*;
2 use std::fmt::Debug;
3
check<I>(iter: I) where I: ParallelIterator + Debug,4 fn check<I>(iter: I)
5 where
6 I: ParallelIterator + Debug,
7 {
8 println!("{:?}", iter);
9 }
10
11 #[test]
debug_binary_heap()12 fn debug_binary_heap() {
13 use std::collections::BinaryHeap;
14 let mut heap: BinaryHeap<_> = (0..10).collect();
15 check(heap.par_iter());
16 check(heap.par_drain());
17 check(heap.into_par_iter());
18 }
19
20 #[test]
debug_btree_map()21 fn debug_btree_map() {
22 use std::collections::BTreeMap;
23 let mut map: BTreeMap<_, _> = (0..10).enumerate().collect();
24 check(map.par_iter());
25 check(map.par_iter_mut());
26 check(map.into_par_iter());
27 }
28
29 #[test]
debug_btree_set()30 fn debug_btree_set() {
31 use std::collections::BTreeSet;
32 let set: BTreeSet<_> = (0..10).collect();
33 check(set.par_iter());
34 check(set.into_par_iter());
35 }
36
37 #[test]
debug_hash_map()38 fn debug_hash_map() {
39 use std::collections::HashMap;
40 let mut map: HashMap<_, _> = (0..10).enumerate().collect();
41 check(map.par_iter());
42 check(map.par_iter_mut());
43 check(map.par_drain());
44 check(map.into_par_iter());
45 }
46
47 #[test]
debug_hash_set()48 fn debug_hash_set() {
49 use std::collections::HashSet;
50 let mut set: HashSet<_> = (0..10).collect();
51 check(set.par_iter());
52 check(set.par_drain());
53 check(set.into_par_iter());
54 }
55
56 #[test]
debug_linked_list()57 fn debug_linked_list() {
58 use std::collections::LinkedList;
59 let mut list: LinkedList<_> = (0..10).collect();
60 check(list.par_iter());
61 check(list.par_iter_mut());
62 check(list.into_par_iter());
63 }
64
65 #[test]
debug_vec_deque()66 fn debug_vec_deque() {
67 use std::collections::VecDeque;
68 let mut deque: VecDeque<_> = (0..10).collect();
69 check(deque.par_iter());
70 check(deque.par_iter_mut());
71 check(deque.par_drain(..));
72 check(deque.into_par_iter());
73 }
74
75 #[test]
debug_option()76 fn debug_option() {
77 let mut option = Some(0);
78 check(option.par_iter());
79 check(option.par_iter_mut());
80 check(option.into_par_iter());
81 }
82
83 #[test]
debug_result()84 fn debug_result() {
85 let mut result = Ok::<_, ()>(0);
86 check(result.par_iter());
87 check(result.par_iter_mut());
88 check(result.into_par_iter());
89 }
90
91 #[test]
debug_range()92 fn debug_range() {
93 check((0..10).into_par_iter());
94 }
95
96 #[test]
debug_range_inclusive()97 fn debug_range_inclusive() {
98 check((0..=10).into_par_iter());
99 }
100
101 #[test]
debug_str()102 fn debug_str() {
103 let s = "a b c d\ne f g";
104 check(s.par_chars());
105 check(s.par_lines());
106 check(s.par_split('\n'));
107 check(s.par_split_terminator('\n'));
108 check(s.par_split_whitespace());
109 }
110
111 #[test]
debug_string()112 fn debug_string() {
113 let mut s = "a b c d\ne f g".to_string();
114 s.par_drain(..);
115 }
116
117 #[test]
debug_vec()118 fn debug_vec() {
119 let mut v: Vec<_> = (0..10).collect();
120 check(v.par_iter());
121 check(v.par_iter_mut());
122 check(v.par_chunks(42));
123 check(v.par_chunks_exact(42));
124 check(v.par_chunks_mut(42));
125 check(v.par_chunks_exact_mut(42));
126 check(v.par_windows(42));
127 check(v.par_split(|x| x % 3 == 0));
128 check(v.par_split_mut(|x| x % 3 == 0));
129 check(v.par_drain(..));
130 check(v.into_par_iter());
131 }
132
133 #[test]
debug_array()134 fn debug_array() {
135 let a = [0i32; 10];
136 check(a.into_par_iter());
137 }
138
139 #[test]
debug_adaptors()140 fn debug_adaptors() {
141 let v: Vec<_> = (0..10).collect();
142 check(v.par_iter().chain(&v));
143 check(v.par_iter().cloned());
144 check(v.par_iter().copied());
145 check(v.par_iter().enumerate());
146 check(v.par_iter().filter(|_| true));
147 check(v.par_iter().filter_map(Some));
148 check(v.par_iter().flat_map(Some));
149 check(v.par_iter().flat_map_iter(Some));
150 check(v.par_iter().map(Some).flatten());
151 check(v.par_iter().map(Some).flatten_iter());
152 check(v.par_iter().fold(|| 0, |x, _| x));
153 check(v.par_iter().fold_with(0, |x, _| x));
154 check(v.par_iter().try_fold(|| 0, |x, _| Some(x)));
155 check(v.par_iter().try_fold_with(0, |x, _| Some(x)));
156 check(v.par_iter().inspect(|_| ()));
157 check(v.par_iter().update(|_| ()));
158 check(v.par_iter().interleave(&v));
159 check(v.par_iter().interleave_shortest(&v));
160 check(v.par_iter().intersperse(&-1));
161 check(v.par_iter().chunks(3));
162 check(v.par_iter().map(|x| x));
163 check(v.par_iter().map_with(0, |_, x| x));
164 check(v.par_iter().map_init(|| 0, |_, x| x));
165 check(v.par_iter().panic_fuse());
166 check(v.par_iter().positions(|_| true));
167 check(v.par_iter().rev());
168 check(v.par_iter().skip(1));
169 check(v.par_iter().take(1));
170 check(v.par_iter().map(Some).while_some());
171 check(v.par_iter().with_max_len(1));
172 check(v.par_iter().with_min_len(1));
173 check(v.par_iter().zip(&v));
174 check(v.par_iter().zip_eq(&v));
175 check(v.par_iter().step_by(2));
176 }
177
178 #[test]
debug_empty()179 fn debug_empty() {
180 check(rayon::iter::empty::<i32>());
181 }
182
183 #[test]
debug_once()184 fn debug_once() {
185 check(rayon::iter::once(10));
186 }
187
188 #[test]
debug_repeat()189 fn debug_repeat() {
190 let x: Option<i32> = None;
191 check(rayon::iter::repeat(x));
192 check(rayon::iter::repeatn(x, 10));
193 }
194
195 #[test]
debug_splitter()196 fn debug_splitter() {
197 check(rayon::iter::split(0..10, |x| (x, None)));
198 }
199
200 #[test]
debug_multizip()201 fn debug_multizip() {
202 let v: &Vec<_> = &(0..10).collect();
203 check((v,).into_par_iter());
204 check((v, v).into_par_iter());
205 check((v, v, v).into_par_iter());
206 check((v, v, v, v).into_par_iter());
207 check((v, v, v, v, v).into_par_iter());
208 check((v, v, v, v, v, v).into_par_iter());
209 check((v, v, v, v, v, v, v).into_par_iter());
210 check((v, v, v, v, v, v, v, v).into_par_iter());
211 check((v, v, v, v, v, v, v, v, v).into_par_iter());
212 check((v, v, v, v, v, v, v, v, v, v).into_par_iter());
213 check((v, v, v, v, v, v, v, v, v, v, v).into_par_iter());
214 check((v, v, v, v, v, v, v, v, v, v, v, v).into_par_iter());
215 }
216