Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stabilize hash_extract_if #134655

Merged
merged 1 commit into from
Feb 25, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 5 additions & 8 deletions library/std/src/collections/hash/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -659,7 +659,6 @@ impl<K, V, S> HashMap<K, V, S> {
/// Splitting a map into even and odd keys, reusing the original map:
///
/// ```
/// #![feature(hash_extract_if)]
/// use std::collections::HashMap;
///
/// let mut map: HashMap<i32, i32> = (0..8).map(|x| (x, x)).collect();
Expand All @@ -675,7 +674,7 @@ impl<K, V, S> HashMap<K, V, S> {
/// ```
#[inline]
#[rustc_lint_query_instability]
#[unstable(feature = "hash_extract_if", issue = "59618")]
#[stable(feature = "hash_extract_if", since = "CURRENT_RUSTC_VERSION")]
pub fn extract_if<F>(&mut self, pred: F) -> ExtractIf<'_, K, V, F>
where
F: FnMut(&K, &mut V) -> bool,
Expand Down Expand Up @@ -1718,16 +1717,14 @@ impl<'a, K, V> Drain<'a, K, V> {
/// # Example
///
/// ```
/// #![feature(hash_extract_if)]
///
/// use std::collections::HashMap;
///
/// let mut map = HashMap::from([
/// ("a", 1),
/// ]);
/// let iter = map.extract_if(|_k, v| *v % 2 == 0);
/// ```
#[unstable(feature = "hash_extract_if", issue = "59618")]
#[stable(feature = "hash_extract_if", since = "CURRENT_RUSTC_VERSION")]
#[must_use = "iterators are lazy and do nothing unless consumed"]
pub struct ExtractIf<'a, K, V, F>
where
Expand Down Expand Up @@ -2742,7 +2739,7 @@ where
}
}

#[unstable(feature = "hash_extract_if", issue = "59618")]
#[stable(feature = "hash_extract_if", since = "CURRENT_RUSTC_VERSION")]
impl<K, V, F> Iterator for ExtractIf<'_, K, V, F>
where
F: FnMut(&K, &mut V) -> bool,
Expand All @@ -2759,10 +2756,10 @@ where
}
}

#[unstable(feature = "hash_extract_if", issue = "59618")]
#[stable(feature = "hash_extract_if", since = "CURRENT_RUSTC_VERSION")]
impl<K, V, F> FusedIterator for ExtractIf<'_, K, V, F> where F: FnMut(&K, &mut V) -> bool {}

#[unstable(feature = "hash_extract_if", issue = "59618")]
#[stable(feature = "hash_extract_if", since = "CURRENT_RUSTC_VERSION")]
impl<'a, K, V, F> fmt::Debug for ExtractIf<'a, K, V, F>
where
F: FnMut(&K, &mut V) -> bool,
Expand Down
13 changes: 5 additions & 8 deletions library/std/src/collections/hash/set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,6 @@ impl<T, S> HashSet<T, S> {
/// Splitting a set into even and odd values, reusing the original set:
///
/// ```
/// #![feature(hash_extract_if)]
/// use std::collections::HashSet;
///
/// let mut set: HashSet<i32> = (0..8).collect();
Expand All @@ -309,7 +308,7 @@ impl<T, S> HashSet<T, S> {
/// ```
#[inline]
#[rustc_lint_query_instability]
#[unstable(feature = "hash_extract_if", issue = "59618")]
#[stable(feature = "hash_extract_if", since = "CURRENT_RUSTC_VERSION")]
pub fn extract_if<F>(&mut self, pred: F) -> ExtractIf<'_, T, F>
where
F: FnMut(&T) -> bool,
Expand Down Expand Up @@ -1383,15 +1382,13 @@ pub struct Drain<'a, K: 'a> {
/// # Examples
///
/// ```
/// #![feature(hash_extract_if)]
///
/// use std::collections::HashSet;
///
/// let mut a = HashSet::from([1, 2, 3]);
///
/// let mut extract_ifed = a.extract_if(|v| v % 2 == 0);
/// ```
#[unstable(feature = "hash_extract_if", issue = "59618")]
#[stable(feature = "hash_extract_if", since = "CURRENT_RUSTC_VERSION")]
pub struct ExtractIf<'a, K, F>
where
F: FnMut(&K) -> bool,
Expand Down Expand Up @@ -1674,7 +1671,7 @@ impl<K: fmt::Debug> fmt::Debug for Drain<'_, K> {
}
}

#[unstable(feature = "hash_extract_if", issue = "59618")]
#[stable(feature = "hash_extract_if", since = "CURRENT_RUSTC_VERSION")]
impl<K, F> Iterator for ExtractIf<'_, K, F>
where
F: FnMut(&K) -> bool,
Expand All @@ -1691,10 +1688,10 @@ where
}
}

#[unstable(feature = "hash_extract_if", issue = "59618")]
#[stable(feature = "hash_extract_if", since = "CURRENT_RUSTC_VERSION")]
impl<K, F> FusedIterator for ExtractIf<'_, K, F> where F: FnMut(&K) -> bool {}

#[unstable(feature = "hash_extract_if", issue = "59618")]
#[stable(feature = "hash_extract_if", since = "CURRENT_RUSTC_VERSION")]
impl<'a, K, F> fmt::Debug for ExtractIf<'a, K, F>
where
F: FnMut(&K) -> bool,
Expand Down
Loading