amadeus_core/into_par_stream/
collections.rs1use owned_chars::{OwnedChars as IntoChars, OwnedCharsExt};
2use std::{
3 collections::{
4 binary_heap, btree_map, btree_set, hash_map, hash_set, linked_list, vec_deque, BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, LinkedList, VecDeque
5 }, hash::{BuildHasher, Hash}, iter, option, result, slice, str, vec
6};
7
8use super::{IntoDistributedStream, IntoParallelStream, IterDistStream, IterParStream};
9use crate::pool::ProcessSend;
10
11pub struct TupleCloned<I: Iterator>(I);
12impl<'a, 'b, I: Iterator<Item = (&'a A, &'b B)>, A: Clone + 'a, B: Clone + 'b> Iterator
13 for TupleCloned<I>
14{
15 type Item = (A, B);
16
17 #[inline(always)]
18 fn next(&mut self) -> Option<Self::Item> {
19 self.0.next().map(|(a, b)| (a.clone(), b.clone()))
20 }
21}
22
23impl_par_dist_rename! {
24 impl<T> IntoParallelStream for Vec<T>
25 where
26 T: Send + 'static,
27 {
28 type ParStream = IterParStream<vec::IntoIter<T>>;
29 type Item = T;
30
31 #[inline(always)]
32 fn into_par_stream(self) -> Self::ParStream
33 where
34 Self: Sized,
35 {
36 IterParStream(self.into_iter())
37 }
38 }
39 impl<'a, T: Clone> IntoParallelStream for &'a Vec<T>
40 where
41 T: Send + 'static,
42 {
43 type ParStream = IterParStream<iter::Cloned<slice::Iter<'a, T>>>;
44 type Item = T;
45
46 #[inline(always)]
47 fn into_par_stream(self) -> Self::ParStream
48 where
49 Self: Sized,
50 {
51 IterParStream(self.iter().cloned())
52 }
53 }
54
55 impl<T> IntoParallelStream for VecDeque<T>
56 where
57 T: Send + 'static,
58 {
59 type ParStream = IterParStream<vec_deque::IntoIter<T>>;
60 type Item = T;
61
62 #[inline(always)]
63 fn into_par_stream(self) -> Self::ParStream
64 where
65 Self: Sized,
66 {
67 IterParStream(self.into_iter())
68 }
69 }
70 impl<'a, T: Clone> IntoParallelStream for &'a VecDeque<T>
71 where
72 T: Send + 'static,
73 {
74 type ParStream = IterParStream<iter::Cloned<vec_deque::Iter<'a, T>>>;
75 type Item = T;
76
77 #[inline(always)]
78 fn into_par_stream(self) -> Self::ParStream
79 where
80 Self: Sized,
81 {
82 IterParStream(self.iter().cloned())
83 }
84 }
85
86 impl<T: Ord> IntoParallelStream for BinaryHeap<T>
87 where
88 T: Send + 'static,
89 {
90 type ParStream = IterParStream<binary_heap::IntoIter<T>>;
91 type Item = T;
92
93 #[inline(always)]
94 fn into_par_stream(self) -> Self::ParStream
95 where
96 Self: Sized,
97 {
98 IterParStream(self.into_iter())
99 }
100 }
101 impl<'a, T: Ord + Clone> IntoParallelStream for &'a BinaryHeap<T>
102 where
103 T: Send + 'static,
104 {
105 type ParStream = IterParStream<iter::Cloned<binary_heap::Iter<'a, T>>>;
106 type Item = T;
107
108 #[inline(always)]
109 fn into_par_stream(self) -> Self::ParStream
110 where
111 Self: Sized,
112 {
113 IterParStream(self.iter().cloned())
114 }
115 }
116
117 impl<T> IntoParallelStream for LinkedList<T>
118 where
119 T: Send + 'static,
120 {
121 type ParStream = IterParStream<linked_list::IntoIter<T>>;
122 type Item = T;
123
124 #[inline(always)]
125 fn into_par_stream(self) -> Self::ParStream
126 where
127 Self: Sized,
128 {
129 IterParStream(self.into_iter())
130 }
131 }
132 impl<'a, T: Clone> IntoParallelStream for &'a LinkedList<T>
133 where
134 T: Send + 'static,
135 {
136 type ParStream = IterParStream<iter::Cloned<linked_list::Iter<'a, T>>>;
137 type Item = T;
138
139 #[inline(always)]
140 fn into_par_stream(self) -> Self::ParStream
141 where
142 Self: Sized,
143 {
144 IterParStream(self.iter().cloned())
145 }
146 }
147
148 impl<T, S> IntoParallelStream for HashSet<T, S>
149 where
150 T: Eq + Hash + Send + 'static,
151 S: BuildHasher + Default,
152 {
153 type ParStream = IterParStream<hash_set::IntoIter<T>>;
154 type Item = T;
155
156 #[inline(always)]
157 fn into_par_stream(self) -> Self::ParStream
158 where
159 Self: Sized,
160 {
161 IterParStream(self.into_iter())
162 }
163 }
164 impl<'a, T: Clone, S> IntoParallelStream for &'a HashSet<T, S>
165 where
166 T: Eq + Hash + Send + 'static,
167 S: BuildHasher + Default,
168 {
169 type ParStream = IterParStream<iter::Cloned<hash_set::Iter<'a, T>>>;
170 type Item = T;
171
172 #[inline(always)]
173 fn into_par_stream(self) -> Self::ParStream
174 where
175 Self: Sized,
176 {
177 IterParStream(self.iter().cloned())
178 }
179 }
180
181 impl<K, V, S> IntoParallelStream for HashMap<K, V, S>
182 where
183 K: Eq + Hash + Send + 'static,
184 V: Send + 'static,
185 S: BuildHasher + Default,
186 {
187 type ParStream = IterParStream<hash_map::IntoIter<K, V>>;
188 type Item = (K, V);
189
190 #[inline(always)]
191 fn into_par_stream(self) -> Self::ParStream
192 where
193 Self: Sized,
194 {
195 IterParStream(self.into_iter())
196 }
197 }
198 impl<'a, K: Clone, V: Clone, S> IntoParallelStream for &'a HashMap<K, V, S>
199 where
200 K: Eq + Hash + Send + 'static,
201 V: Send + 'static,
202 S: BuildHasher + Default,
203 {
204 type ParStream = IterParStream<TupleCloned<hash_map::Iter<'a, K, V>>>;
205 type Item = (K, V);
206
207 #[inline(always)]
208 fn into_par_stream(self) -> Self::ParStream
209 where
210 Self: Sized,
211 {
212 IterParStream(TupleCloned(self.iter()))
213 }
214 }
215
216 impl<T> IntoParallelStream for BTreeSet<T>
217 where
218 T: Send + 'static,
219 {
220 type ParStream = IterParStream<btree_set::IntoIter<T>>;
221 type Item = T;
222
223 #[inline(always)]
224 fn into_par_stream(self) -> Self::ParStream
225 where
226 Self: Sized,
227 {
228 IterParStream(self.into_iter())
229 }
230 }
231 impl<'a, T: Clone> IntoParallelStream for &'a BTreeSet<T>
232 where
233 T: Send + 'static,
234 {
235 type ParStream = IterParStream<iter::Cloned<btree_set::Iter<'a, T>>>;
236 type Item = T;
237
238 #[inline(always)]
239 fn into_par_stream(self) -> Self::ParStream
240 where
241 Self: Sized,
242 {
243 IterParStream(self.iter().cloned())
244 }
245 }
246
247 impl<K, V> IntoParallelStream for BTreeMap<K, V>
248 where
249 K: Send + 'static,
250 V: Send + 'static,
251 {
252 type ParStream = IterParStream<btree_map::IntoIter<K, V>>;
253 type Item = (K, V);
254
255 #[inline(always)]
256 fn into_par_stream(self) -> Self::ParStream
257 where
258 Self: Sized,
259 {
260 IterParStream(self.into_iter())
261 }
262 }
263 impl<'a, K: Clone, V: Clone> IntoParallelStream for &'a BTreeMap<K, V>
264 where
265 K: Send + 'static,
266 V: Send + 'static,
267 {
268 type ParStream = IterParStream<TupleCloned<btree_map::Iter<'a, K, V>>>;
269 type Item = (K, V);
270
271 #[inline(always)]
272 fn into_par_stream(self) -> Self::ParStream
273 where
274 Self: Sized,
275 {
276 IterParStream(TupleCloned(self.iter()))
277 }
278 }
279
280 impl IntoParallelStream for String {
281 type ParStream = IterParStream<IntoChars>;
282 type Item = char;
283
284 #[inline(always)]
285 fn into_par_stream(self) -> Self::ParStream
286 where
287 Self: Sized,
288 {
289 IterParStream(self.into_chars())
290 }
291 }
292 impl<'a> IntoParallelStream for &'a String {
293 type ParStream = IterParStream<str::Chars<'a>>;
294 type Item = char;
295
296 #[inline(always)]
297 fn into_par_stream(self) -> Self::ParStream
298 where
299 Self: Sized,
300 {
301 IterParStream(self.chars())
302 }
303 }
304
305 impl<T> IntoParallelStream for Option<T>
306 where
307 T: Send + 'static,
308 {
309 type ParStream = IterParStream<option::IntoIter<T>>;
310 type Item = T;
311
312 #[inline(always)]
313 fn into_par_stream(self) -> Self::ParStream
314 where
315 Self: Sized,
316 {
317 IterParStream(self.into_iter())
318 }
319 }
320 impl<'a, T: Clone> IntoParallelStream for &'a Option<T>
321 where
322 T: Send + 'static,
323 {
324 type ParStream = IterParStream<iter::Cloned<option::Iter<'a, T>>>;
325 type Item = T;
326
327 #[inline(always)]
328 fn into_par_stream(self) -> Self::ParStream
329 where
330 Self: Sized,
331 {
332 IterParStream(self.iter().cloned())
333 }
334 }
335
336 impl<T, E> IntoParallelStream for Result<T, E>
337 where
338 T: Send + 'static,
339 {
340 type ParStream = IterParStream<result::IntoIter<T>>;
341 type Item = T;
342
343 #[inline(always)]
344 fn into_par_stream(self) -> Self::ParStream
345 where
346 Self: Sized,
347 {
348 IterParStream(self.into_iter())
349 }
350 }
351 impl<'a, T: Clone, E> IntoParallelStream for &'a Result<T, E>
352 where
353 T: Send + 'static,
354 {
355 type ParStream = IterParStream<iter::Cloned<result::Iter<'a, T>>>;
356 type Item = T;
357
358 #[inline(always)]
359 fn into_par_stream(self) -> Self::ParStream
360 where
361 Self: Sized,
362 {
363 IterParStream(self.iter().cloned())
364 }
365 }
366}