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_adaptors()134 fn debug_adaptors() {
135 let v: Vec<_> = (0..10).collect();
136 check(v.par_iter().chain(&v));
137 check(v.par_iter().cloned());
138 check(v.par_iter().copied());
139 check(v.par_iter().enumerate());
140 check(v.par_iter().filter(|_| true));
141 check(v.par_iter().filter_map(Some));
142 check(v.par_iter().flat_map(Some));
143 check(v.par_iter().flat_map_iter(Some));
144 check(v.par_iter().map(Some).flatten());
145 check(v.par_iter().map(Some).flatten_iter());
146 check(v.par_iter().fold(|| 0, |x, _| x));
147 check(v.par_iter().fold_with(0, |x, _| x));
148 check(v.par_iter().try_fold(|| 0, |x, _| Some(x)));
149 check(v.par_iter().try_fold_with(0, |x, _| Some(x)));
150 check(v.par_iter().inspect(|_| ()));
151 check(v.par_iter().update(|_| ()));
152 check(v.par_iter().interleave(&v));
153 check(v.par_iter().interleave_shortest(&v));
154 check(v.par_iter().intersperse(&-1));
155 check(v.par_iter().chunks(3));
156 check(v.par_iter().map(|x| x));
157 check(v.par_iter().map_with(0, |_, x| x));
158 check(v.par_iter().map_init(|| 0, |_, x| x));
159 check(v.par_iter().panic_fuse());
160 check(v.par_iter().positions(|_| true));
161 check(v.par_iter().rev());
162 check(v.par_iter().skip(1));
163 check(v.par_iter().take(1));
164 check(v.par_iter().map(Some).while_some());
165 check(v.par_iter().with_max_len(1));
166 check(v.par_iter().with_min_len(1));
167 check(v.par_iter().zip(&v));
168 check(v.par_iter().zip_eq(&v));
169 check(v.par_iter().step_by(2));
170 }
171
172 #[test]
debug_empty()173 fn debug_empty() {
174 check(rayon::iter::empty::<i32>());
175 }
176
177 #[test]
debug_once()178 fn debug_once() {
179 check(rayon::iter::once(10));
180 }
181
182 #[test]
debug_repeat()183 fn debug_repeat() {
184 let x: Option<i32> = None;
185 check(rayon::iter::repeat(x));
186 check(rayon::iter::repeatn(x, 10));
187 }
188
189 #[test]
debug_splitter()190 fn debug_splitter() {
191 check(rayon::iter::split(0..10, |x| (x, None)));
192 }
193
194 #[test]
debug_multizip()195 fn debug_multizip() {
196 let v: &Vec<_> = &(0..10).collect();
197 check((v,).into_par_iter());
198 check((v, v).into_par_iter());
199 check((v, v, v).into_par_iter());
200 check((v, v, v, v).into_par_iter());
201 check((v, v, v, v, v).into_par_iter());
202 check((v, v, v, v, v, v).into_par_iter());
203 check((v, v, v, v, v, v, v).into_par_iter());
204 check((v, v, v, v, v, v, v, v).into_par_iter());
205 check((v, v, v, v, v, v, v, v, v).into_par_iter());
206 check((v, v, v, v, v, v, v, v, v, v).into_par_iter());
207 check((v, v, v, v, v, v, v, v, v, v, v).into_par_iter());
208 check((v, v, v, v, v, v, v, v, v, v, v, v).into_par_iter());
209 }
210