@@ -13,6 +13,7 @@ use crate::vec::Vec;
1313use core:: cmp:: Ordering ;
1414use core:: fmt;
1515use core:: hash:: { BuildHasher , Hash } ;
16+ use core:: ops:: RangeBounds ;
1617
1718use crate :: Bucket ;
1819use crate :: Entries ;
@@ -156,6 +157,43 @@ impl<K: Sync + Send, V: Send> IndexedParallelIterator for ParIterMut<'_, K, V> {
156157 indexed_parallel_iterator_methods ! ( Bucket :: ref_mut) ;
157158}
158159
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+
159197/// Parallel iterator methods and other parallel methods.
160198///
161199/// The following methods **require crate feature `"rayon"`**.
0 commit comments