@@ -13,6 +13,7 @@ use crate::vec::Vec;
13
13
use core:: cmp:: Ordering ;
14
14
use core:: fmt;
15
15
use core:: hash:: { BuildHasher , Hash } ;
16
+ use core:: ops:: RangeBounds ;
16
17
17
18
use crate :: Bucket ;
18
19
use crate :: Entries ;
@@ -156,6 +157,43 @@ impl<K: Sync + Send, V: Send> IndexedParallelIterator for ParIterMut<'_, K, V> {
156
157
indexed_parallel_iterator_methods ! ( Bucket :: ref_mut) ;
157
158
}
158
159
160
+ /// Requires crate feature `"rayon"`.
161
+ impl < ' a , K , V , S > ParallelDrainRange < usize > for & ' a mut IndexMap < K , V , S >
162
+ where
163
+ K : Send ,
164
+ V : Send ,
165
+ {
166
+ type Item = ( K , V ) ;
167
+ type Iter = ParDrain < ' a , K , V > ;
168
+
169
+ fn par_drain < R : RangeBounds < usize > > ( self , range : R ) -> Self :: Iter {
170
+ ParDrain {
171
+ entries : self . core . par_drain ( range) ,
172
+ }
173
+ }
174
+ }
175
+
176
+ /// A parallel draining iterator over the entries of a `IndexMap`.
177
+ ///
178
+ /// This `struct` is created by the [`par_drain`] method on [`IndexMap`]
179
+ /// (provided by rayon's `ParallelDrainRange` trait). See its documentation for more.
180
+ ///
181
+ /// [`par_drain`]: ../struct.IndexMap.html#method.par_drain
182
+ /// [`IndexMap`]: ../struct.IndexMap.html
183
+ pub struct ParDrain < ' a , K : Send , V : Send > {
184
+ entries : rayon:: vec:: Drain < ' a , Bucket < K , V > > ,
185
+ }
186
+
187
+ impl < K : Send , V : Send > ParallelIterator for ParDrain < ' _ , K , V > {
188
+ type Item = ( K , V ) ;
189
+
190
+ parallel_iterator_methods ! ( Bucket :: key_value) ;
191
+ }
192
+
193
+ impl < K : Send , V : Send > IndexedParallelIterator for ParDrain < ' _ , K , V > {
194
+ indexed_parallel_iterator_methods ! ( Bucket :: key_value) ;
195
+ }
196
+
159
197
/// Parallel iterator methods and other parallel methods.
160
198
///
161
199
/// The following methods **require crate feature `"rayon"`**.
0 commit comments