1macro_rules! into_par_vec {
11 ($t:ty => $iter:ident<$($i:tt),*>, impl $($args:tt)*) => {
12 impl $($args)* IntoParallelIterator for $t {
13 type Item = <$t as IntoIterator>::Item;
14 type Iter = $iter<$($i),*>;
15
16 fn into_par_iter(self) -> Self::Iter {
17 use std::iter::FromIterator;
18 $iter { inner: Vec::from_iter(self).into_par_iter() }
19 }
20 }
21 };
22}
23
24pub mod binary_heap;
25pub mod btree_map;
26pub mod btree_set;
27pub mod hash_map;
28pub mod hash_set;
29pub mod linked_list;
30pub mod vec_deque;
31
32use self::drain_guard::DrainGuard;
33
34mod drain_guard {
35 use crate::iter::ParallelDrainRange;
36 use std::mem;
37 use std::ops::RangeBounds;
38
39 #[allow(missing_debug_implementations)]
46 pub(super) struct DrainGuard<'a, T, C: From<Vec<T>>> {
47 collection: &'a mut C,
48 vec: Vec<T>,
49 }
50
51 impl<'a, T, C> DrainGuard<'a, T, C>
52 where
53 C: Default + From<Vec<T>>,
54 Vec<T>: From<C>,
55 {
56 pub(super) fn new(collection: &'a mut C) -> Self {
57 Self {
58 vec: Vec::from(mem::take(collection)),
60 collection,
61 }
62 }
63 }
64
65 impl<'a, T, C: From<Vec<T>>> Drop for DrainGuard<'a, T, C> {
66 fn drop(&mut self) {
67 *self.collection = C::from(mem::take(&mut self.vec));
69 }
70 }
71
72 impl<'a, T, C> ParallelDrainRange<usize> for &'a mut DrainGuard<'_, T, C>
73 where
74 T: Send,
75 C: From<Vec<T>>,
76 {
77 type Iter = crate::vec::Drain<'a, T>;
78 type Item = T;
79
80 fn par_drain<R: RangeBounds<usize>>(self, range: R) -> Self::Iter {
81 self.vec.par_drain(range)
82 }
83 }
84}