@@ -1132,7 +1132,7 @@ impl<K, V, A: Allocator + Clone> BTreeMap<K, V, A> {
1132
1132
K : Ord ,
1133
1133
F : FnMut ( & K , & mut V ) -> bool ,
1134
1134
{
1135
- self . drain_filter ( |k, v| !f ( k, v) ) . for_each ( drop) ;
1135
+ self . extract_if ( |k, v| !f ( k, v) ) . for_each ( drop) ;
1136
1136
}
1137
1137
1138
1138
/// Moves all elements from `other` into `self`, leaving `other` empty.
@@ -1395,7 +1395,7 @@ impl<K, V, A: Allocator + Clone> BTreeMap<K, V, A> {
1395
1395
/// The iterator also lets you mutate the value of each element in the
1396
1396
/// closure, regardless of whether you choose to keep or remove it.
1397
1397
///
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
1399
1399
/// or the iteration short-circuits, then the remaining elements will be retained.
1400
1400
/// Use [`retain`] with a negated predicate if you do not need the returned iterator.
1401
1401
///
@@ -1406,34 +1406,34 @@ impl<K, V, A: Allocator + Clone> BTreeMap<K, V, A> {
1406
1406
/// Splitting a map into even and odd keys, reusing the original map:
1407
1407
///
1408
1408
/// ```
1409
- /// #![feature(btree_drain_filter )]
1409
+ /// #![feature(btree_extract_if )]
1410
1410
/// use std::collections::BTreeMap;
1411
1411
///
1412
1412
/// 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();
1414
1414
/// let odds = map;
1415
1415
/// assert_eq!(evens.keys().copied().collect::<Vec<_>>(), [0, 2, 4, 6]);
1416
1416
/// assert_eq!(odds.keys().copied().collect::<Vec<_>>(), [1, 3, 5, 7]);
1417
1417
/// ```
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 >
1420
1420
where
1421
1421
K : Ord ,
1422
1422
F : FnMut ( & K , & mut V ) -> bool ,
1423
1423
{
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 }
1426
1426
}
1427
1427
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 )
1429
1429
where
1430
1430
K : Ord ,
1431
1431
{
1432
1432
if let Some ( root) = self . root . as_mut ( ) {
1433
1433
let ( root, dormant_root) = DormantMutRef :: new ( root) ;
1434
1434
let front = root. borrow_mut ( ) . first_leaf_edge ( ) ;
1435
1435
(
1436
- DrainFilterInner {
1436
+ ExtractIfInner {
1437
1437
length : & mut self . length ,
1438
1438
dormant_root : Some ( dormant_root) ,
1439
1439
cur_leaf_edge : Some ( front) ,
@@ -1442,7 +1442,7 @@ impl<K, V, A: Allocator + Clone> BTreeMap<K, V, A> {
1442
1442
)
1443
1443
} else {
1444
1444
(
1445
- DrainFilterInner {
1445
+ ExtractIfInner {
1446
1446
length : & mut self . length ,
1447
1447
dormant_root : None ,
1448
1448
cur_leaf_edge : None ,
@@ -1896,10 +1896,10 @@ impl<K, V> Default for Values<'_, K, V> {
1896
1896
}
1897
1897
}
1898
1898
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" ) ]
1901
1901
#[ must_use = "iterators are lazy and do nothing unless consumed" ]
1902
- pub struct DrainFilter <
1902
+ pub struct ExtractIf <
1903
1903
' a ,
1904
1904
K ,
1905
1905
V ,
@@ -1909,13 +1909,13 @@ pub struct DrainFilter<
1909
1909
F : ' a + FnMut ( & K , & mut V ) -> bool ,
1910
1910
{
1911
1911
pred : F ,
1912
- inner : DrainFilterInner < ' a , K , V > ,
1912
+ inner : ExtractIfInner < ' a , K , V > ,
1913
1913
/// The BTreeMap will outlive this IntoIter so we don't care about drop order for `alloc`.
1914
1914
alloc : A ,
1915
1915
}
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 > {
1919
1919
/// Reference to the length field in the borrowed map, updated live.
1920
1920
length : & ' a mut usize ,
1921
1921
/// Buried reference to the root field in the borrowed map.
@@ -1927,20 +1927,20 @@ pub(super) struct DrainFilterInner<'a, K, V> {
1927
1927
cur_leaf_edge : Option < Handle < NodeRef < marker:: Mut < ' a > , K , V , marker:: Leaf > , marker:: Edge > > ,
1928
1928
}
1929
1929
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 >
1932
1932
where
1933
1933
K : fmt:: Debug ,
1934
1934
V : fmt:: Debug ,
1935
1935
F : FnMut ( & K , & mut V ) -> bool ,
1936
1936
{
1937
1937
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 ( )
1939
1939
}
1940
1940
}
1941
1941
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 >
1944
1944
where
1945
1945
F : FnMut ( & K , & mut V ) -> bool ,
1946
1946
{
@@ -1955,14 +1955,14 @@ where
1955
1955
}
1956
1956
}
1957
1957
1958
- impl < ' a , K , V > DrainFilterInner < ' a , K , V > {
1958
+ impl < ' a , K , V > ExtractIfInner < ' a , K , V > {
1959
1959
/// Allow Debug implementations to predict the next element.
1960
1960
pub ( super ) fn peek ( & self ) -> Option < ( & K , & V ) > {
1961
1961
let edge = self . cur_leaf_edge . as_ref ( ) ?;
1962
1962
edge. reborrow ( ) . next_kv ( ) . ok ( ) . map ( Handle :: into_kv)
1963
1963
}
1964
1964
1965
- /// Implementation of a typical `DrainFilter ::next` method, given the predicate.
1965
+ /// Implementation of a typical `ExtractIf ::next` method, given the predicate.
1966
1966
pub ( super ) fn next < F , A : Allocator + Clone > ( & mut self , pred : & mut F , alloc : A ) -> Option < ( K , V ) >
1967
1967
where
1968
1968
F : FnMut ( & K , & mut V ) -> bool ,
@@ -1989,7 +1989,7 @@ impl<'a, K, V> DrainFilterInner<'a, K, V> {
1989
1989
None
1990
1990
}
1991
1991
1992
- /// Implementation of a typical `DrainFilter ::size_hint` method.
1992
+ /// Implementation of a typical `ExtractIf ::size_hint` method.
1993
1993
pub ( super ) fn size_hint ( & self ) -> ( usize , Option < usize > ) {
1994
1994
// In most of the btree iterators, `self.length` is the number of elements
1995
1995
// 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> {
1999
1999
}
2000
2000
}
2001
2001
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 { }
2004
2004
2005
2005
#[ stable( feature = "btree_range" , since = "1.17.0" ) ]
2006
2006
impl < ' a , K , V > Iterator for Range < ' a , K , V > {
0 commit comments