@@ -308,7 +308,8 @@ impl<K, V, S> IndexMap<K, V, S> {
308308 Drain :: new ( self . core . drain ( range) )
309309 }
310310
311- /// Creates an iterator which uses a closure to determine if an element should be removed.
311+ /// Creates an iterator which uses a closure to determine if an element should be removed,
312+ /// for all elements in the given range.
312313 ///
313314 /// If the closure returns true, the element is removed from the map and yielded.
314315 /// If the closure returns false, or panics, the element remains in the map and will not be
@@ -317,6 +318,11 @@ impl<K, V, S> IndexMap<K, V, S> {
317318 /// Note that `extract_if` lets you mutate every value in the filter closure, regardless of
318319 /// whether you choose to keep or remove it.
319320 ///
321+ /// The range may be any type that implements [`RangeBounds<usize>`],
322+ /// including all of the `std::ops::Range*` types, or even a tuple pair of
323+ /// `Bound` start and end values. To check the entire map, use `RangeFull`
324+ /// like `map.extract_if(.., predicate)`.
325+ ///
320326 /// If the returned `ExtractIf` is not exhausted, e.g. because it is dropped without iterating
321327 /// or the iteration short-circuits, then the remaining elements will be retained.
322328 /// Use [`retain`] with a negated predicate if you do not need the returned iterator.
@@ -331,19 +337,20 @@ impl<K, V, S> IndexMap<K, V, S> {
331337 /// use indexmap::IndexMap;
332338 ///
333339 /// let mut map: IndexMap<i32, i32> = (0..8).map(|x| (x, x)).collect();
334- /// let extracted: IndexMap<i32, i32> = map.extract_if(|k, _v| k % 2 == 0).collect();
340+ /// let extracted: IndexMap<i32, i32> = map.extract_if(.., |k, _v| k % 2 == 0).collect();
335341 ///
336342 /// let evens = extracted.keys().copied().collect::<Vec<_>>();
337343 /// let odds = map.keys().copied().collect::<Vec<_>>();
338344 ///
339345 /// assert_eq!(evens, vec![0, 2, 4, 6]);
340346 /// assert_eq!(odds, vec![1, 3, 5, 7]);
341347 /// ```
342- pub fn extract_if < F > ( & mut self , pred : F ) -> ExtractIf < ' _ , K , V , F >
348+ pub fn extract_if < F , R > ( & mut self , range : R , pred : F ) -> ExtractIf < ' _ , K , V , F >
343349 where
344350 F : FnMut ( & K , & mut V ) -> bool ,
351+ R : RangeBounds < usize > ,
345352 {
346- ExtractIf :: new ( & mut self . core , pred)
353+ ExtractIf :: new ( & mut self . core , range , pred)
347354 }
348355
349356 /// Splits the collection into two at the given index.
0 commit comments