@@ -1132,7 +1132,7 @@ impl<K, V, A: Allocator + Clone> BTreeMap<K, V, A> {
11321132 K : Ord ,
11331133 F : FnMut ( & K , & mut V ) -> bool ,
11341134 {
1135- self . drain_filter ( |k, v| !f ( k, v) ) . for_each ( drop) ;
1135+ self . extract_if ( |k, v| !f ( k, v) ) . for_each ( drop) ;
11361136 }
11371137
11381138 /// Moves all elements from `other` into `self`, leaving `other` empty.
@@ -1395,7 +1395,7 @@ impl<K, V, A: Allocator + Clone> BTreeMap<K, V, A> {
13951395 /// The iterator also lets you mutate the value of each element in the
13961396 /// closure, regardless of whether you choose to keep or remove it.
13971397 ///
1398- /// If the returned `DrainFilter ` is not exhausted, e.g. because it is dropped without iterating
1398+ /// If the returned `ExtractIf ` is not exhausted, e.g. because it is dropped without iterating
13991399 /// or the iteration short-circuits, then the remaining elements will be retained.
14001400 /// Use [`retain`] with a negated predicate if you do not need the returned iterator.
14011401 ///
@@ -1406,34 +1406,34 @@ impl<K, V, A: Allocator + Clone> BTreeMap<K, V, A> {
14061406 /// Splitting a map into even and odd keys, reusing the original map:
14071407 ///
14081408 /// ```
1409- /// #![feature(btree_drain_filter )]
1409+ /// #![feature(btree_extract_if )]
14101410 /// use std::collections::BTreeMap;
14111411 ///
14121412 /// let mut map: BTreeMap<i32, i32> = (0..8).map(|x| (x, x)).collect();
1413- /// let evens: BTreeMap<_, _> = map.drain_filter (|k, _v| k % 2 == 0).collect();
1413+ /// let evens: BTreeMap<_, _> = map.extract_if (|k, _v| k % 2 == 0).collect();
14141414 /// let odds = map;
14151415 /// assert_eq!(evens.keys().copied().collect::<Vec<_>>(), [0, 2, 4, 6]);
14161416 /// assert_eq!(odds.keys().copied().collect::<Vec<_>>(), [1, 3, 5, 7]);
14171417 /// ```
1418- #[ unstable( feature = "btree_drain_filter " , issue = "70530" ) ]
1419- pub fn drain_filter < F > ( & mut self , pred : F ) -> DrainFilter < ' _ , K , V , F , A >
1418+ #[ unstable( feature = "btree_extract_if " , issue = "70530" ) ]
1419+ pub fn extract_if < F > ( & mut self , pred : F ) -> ExtractIf < ' _ , K , V , F , A >
14201420 where
14211421 K : Ord ,
14221422 F : FnMut ( & K , & mut V ) -> bool ,
14231423 {
1424- let ( inner, alloc) = self . drain_filter_inner ( ) ;
1425- DrainFilter { pred, inner, alloc }
1424+ let ( inner, alloc) = self . extract_if_inner ( ) ;
1425+ ExtractIf { pred, inner, alloc }
14261426 }
14271427
1428- pub ( super ) fn drain_filter_inner ( & mut self ) -> ( DrainFilterInner < ' _ , K , V > , A )
1428+ pub ( super ) fn extract_if_inner ( & mut self ) -> ( ExtractIfInner < ' _ , K , V > , A )
14291429 where
14301430 K : Ord ,
14311431 {
14321432 if let Some ( root) = self . root . as_mut ( ) {
14331433 let ( root, dormant_root) = DormantMutRef :: new ( root) ;
14341434 let front = root. borrow_mut ( ) . first_leaf_edge ( ) ;
14351435 (
1436- DrainFilterInner {
1436+ ExtractIfInner {
14371437 length : & mut self . length ,
14381438 dormant_root : Some ( dormant_root) ,
14391439 cur_leaf_edge : Some ( front) ,
@@ -1442,7 +1442,7 @@ impl<K, V, A: Allocator + Clone> BTreeMap<K, V, A> {
14421442 )
14431443 } else {
14441444 (
1445- DrainFilterInner {
1445+ ExtractIfInner {
14461446 length : & mut self . length ,
14471447 dormant_root : None ,
14481448 cur_leaf_edge : None ,
@@ -1896,10 +1896,10 @@ impl<K, V> Default for Values<'_, K, V> {
18961896 }
18971897}
18981898
1899- /// An iterator produced by calling `drain_filter ` on BTreeMap.
1900- #[ unstable( feature = "btree_drain_filter " , issue = "70530" ) ]
1899+ /// An iterator produced by calling `extract_if ` on BTreeMap.
1900+ #[ unstable( feature = "btree_extract_if " , issue = "70530" ) ]
19011901#[ must_use = "iterators are lazy and do nothing unless consumed" ]
1902- pub struct DrainFilter <
1902+ pub struct ExtractIf <
19031903 ' a ,
19041904 K ,
19051905 V ,
@@ -1909,13 +1909,13 @@ pub struct DrainFilter<
19091909 F : ' a + FnMut ( & K , & mut V ) -> bool ,
19101910{
19111911 pred : F ,
1912- inner : DrainFilterInner < ' a , K , V > ,
1912+ inner : ExtractIfInner < ' a , K , V > ,
19131913 /// The BTreeMap will outlive this IntoIter so we don't care about drop order for `alloc`.
19141914 alloc : A ,
19151915}
1916- /// Most of the implementation of DrainFilter are generic over the type
1917- /// of the predicate, thus also serving for BTreeSet::DrainFilter .
1918- pub ( super ) struct DrainFilterInner < ' a , K , V > {
1916+ /// Most of the implementation of ExtractIf are generic over the type
1917+ /// of the predicate, thus also serving for BTreeSet::ExtractIf .
1918+ pub ( super ) struct ExtractIfInner < ' a , K , V > {
19191919 /// Reference to the length field in the borrowed map, updated live.
19201920 length : & ' a mut usize ,
19211921 /// Buried reference to the root field in the borrowed map.
@@ -1927,20 +1927,20 @@ pub(super) struct DrainFilterInner<'a, K, V> {
19271927 cur_leaf_edge : Option < Handle < NodeRef < marker:: Mut < ' a > , K , V , marker:: Leaf > , marker:: Edge > > ,
19281928}
19291929
1930- #[ unstable( feature = "btree_drain_filter " , issue = "70530" ) ]
1931- impl < K , V , F > fmt:: Debug for DrainFilter < ' _ , K , V , F >
1930+ #[ unstable( feature = "btree_extract_if " , issue = "70530" ) ]
1931+ impl < K , V , F > fmt:: Debug for ExtractIf < ' _ , K , V , F >
19321932where
19331933 K : fmt:: Debug ,
19341934 V : fmt:: Debug ,
19351935 F : FnMut ( & K , & mut V ) -> bool ,
19361936{
19371937 fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
1938- f. debug_tuple ( "DrainFilter " ) . field ( & self . inner . peek ( ) ) . finish ( )
1938+ f. debug_tuple ( "ExtractIf " ) . field ( & self . inner . peek ( ) ) . finish ( )
19391939 }
19401940}
19411941
1942- #[ unstable( feature = "btree_drain_filter " , issue = "70530" ) ]
1943- impl < K , V , F , A : Allocator + Clone > Iterator for DrainFilter < ' _ , K , V , F , A >
1942+ #[ unstable( feature = "btree_extract_if " , issue = "70530" ) ]
1943+ impl < K , V , F , A : Allocator + Clone > Iterator for ExtractIf < ' _ , K , V , F , A >
19441944where
19451945 F : FnMut ( & K , & mut V ) -> bool ,
19461946{
@@ -1955,14 +1955,14 @@ where
19551955 }
19561956}
19571957
1958- impl < ' a , K , V > DrainFilterInner < ' a , K , V > {
1958+ impl < ' a , K , V > ExtractIfInner < ' a , K , V > {
19591959 /// Allow Debug implementations to predict the next element.
19601960 pub ( super ) fn peek ( & self ) -> Option < ( & K , & V ) > {
19611961 let edge = self . cur_leaf_edge . as_ref ( ) ?;
19621962 edge. reborrow ( ) . next_kv ( ) . ok ( ) . map ( Handle :: into_kv)
19631963 }
19641964
1965- /// Implementation of a typical `DrainFilter ::next` method, given the predicate.
1965+ /// Implementation of a typical `ExtractIf ::next` method, given the predicate.
19661966 pub ( super ) fn next < F , A : Allocator + Clone > ( & mut self , pred : & mut F , alloc : A ) -> Option < ( K , V ) >
19671967 where
19681968 F : FnMut ( & K , & mut V ) -> bool ,
@@ -1989,7 +1989,7 @@ impl<'a, K, V> DrainFilterInner<'a, K, V> {
19891989 None
19901990 }
19911991
1992- /// Implementation of a typical `DrainFilter ::size_hint` method.
1992+ /// Implementation of a typical `ExtractIf ::size_hint` method.
19931993 pub ( super ) fn size_hint ( & self ) -> ( usize , Option < usize > ) {
19941994 // In most of the btree iterators, `self.length` is the number of elements
19951995 // yet to be visited. Here, it includes elements that were visited and that
@@ -1999,8 +1999,8 @@ impl<'a, K, V> DrainFilterInner<'a, K, V> {
19991999 }
20002000}
20012001
2002- #[ unstable( feature = "btree_drain_filter " , issue = "70530" ) ]
2003- impl < K , V , F > FusedIterator for DrainFilter < ' _ , K , V , F > where F : FnMut ( & K , & mut V ) -> bool { }
2002+ #[ unstable( feature = "btree_extract_if " , issue = "70530" ) ]
2003+ impl < K , V , F > FusedIterator for ExtractIf < ' _ , K , V , F > where F : FnMut ( & K , & mut V ) -> bool { }
20042004
20052005#[ stable( feature = "btree_range" , since = "1.17.0" ) ]
20062006impl < ' a , K , V > Iterator for Range < ' a , K , V > {
0 commit comments