diff options
| author | The 8472 <git@infinite-source.de> | 2023-04-09 00:37:21 +0200 |
|---|---|---|
| committer | The 8472 <git@infinite-source.de> | 2023-06-14 09:28:54 +0200 |
| commit | 114d5f221c135e3267fbb966e2f0e582361cd8cb (patch) | |
| tree | dad53dfcb27f054304ae5f49b6ff1994a9fb4e0a /library/alloc/src/vec | |
| parent | b7ce7edd87c984997137eb067df2a32d4d66470c (diff) | |
s/drain_filter/extract_if/ for Vec, Btree{Map,Set} and LinkedList
Diffstat (limited to 'library/alloc/src/vec')
| -rw-r--r-- | library/alloc/src/vec/extract_if.rs (renamed from library/alloc/src/vec/drain_filter.rs) | 22 | ||||
| -rw-r--r-- | library/alloc/src/vec/mod.rs | 22 |
2 files changed, 22 insertions, 22 deletions
diff --git a/library/alloc/src/vec/drain_filter.rs b/library/alloc/src/vec/extract_if.rs index ebee3d6eca0..e8e6bd56d21 100644 --- a/library/alloc/src/vec/drain_filter.rs +++ b/library/alloc/src/vec/extract_if.rs @@ -6,21 +6,21 @@ use super::Vec; /// An iterator which uses a closure to determine if an element should be removed. /// -/// This struct is created by [`Vec::drain_filter`]. +/// This struct is created by [`Vec::extract_if`]. /// See its documentation for more. /// /// # Example /// /// ``` -/// #![feature(drain_filter)] +/// #![feature(extract_if)] /// /// let mut v = vec![0, 1, 2]; -/// let iter: std::vec::DrainFilter<'_, _, _> = v.drain_filter(|x| *x % 2 == 0); +/// let iter: std::vec::ExtractIf<'_, _, _> = v.extract_if(|x| *x % 2 == 0); /// ``` -#[unstable(feature = "drain_filter", reason = "recently added", issue = "43244")] +#[unstable(feature = "extract_if", reason = "recently added", issue = "43244")] #[derive(Debug)] #[must_use = "iterators are lazy and do nothing unless consumed"] -pub struct DrainFilter< +pub struct ExtractIf< 'a, T, F, @@ -39,13 +39,13 @@ pub struct DrainFilter< pub(super) pred: F, /// A flag that indicates a panic has occurred in the filter test predicate. /// This is used as a hint in the drop implementation to prevent consumption - /// of the remainder of the `DrainFilter`. Any unprocessed items will be + /// of the remainder of the `ExtractIf`. Any unprocessed items will be /// backshifted in the `vec`, but no further items will be dropped or /// tested by the filter predicate. pub(super) panic_flag: bool, } -impl<T, F, A: Allocator> DrainFilter<'_, T, F, A> +impl<T, F, A: Allocator> ExtractIf<'_, T, F, A> where F: FnMut(&mut T) -> bool, { @@ -57,8 +57,8 @@ where } } -#[unstable(feature = "drain_filter", reason = "recently added", issue = "43244")] -impl<T, F, A: Allocator> Iterator for DrainFilter<'_, T, F, A> +#[unstable(feature = "extract_if", reason = "recently added", issue = "43244")] +impl<T, F, A: Allocator> Iterator for ExtractIf<'_, T, F, A> where F: FnMut(&mut T) -> bool, { @@ -95,8 +95,8 @@ where } } -#[unstable(feature = "drain_filter", reason = "recently added", issue = "43244")] -impl<T, F, A: Allocator> Drop for DrainFilter<'_, T, F, A> +#[unstable(feature = "extract_if", reason = "recently added", issue = "43244")] +impl<T, F, A: Allocator> Drop for ExtractIf<'_, T, F, A> where F: FnMut(&mut T) -> bool, { diff --git a/library/alloc/src/vec/mod.rs b/library/alloc/src/vec/mod.rs index 75f1a96c4c4..289bbc7d2ef 100644 --- a/library/alloc/src/vec/mod.rs +++ b/library/alloc/src/vec/mod.rs @@ -71,10 +71,10 @@ use crate::boxed::Box; use crate::collections::TryReserveError; use crate::raw_vec::RawVec; -#[unstable(feature = "drain_filter", reason = "recently added", issue = "43244")] -pub use self::drain_filter::DrainFilter; +#[unstable(feature = "extract_if", reason = "recently added", issue = "43244")] +pub use self::extract_if::ExtractIf; -mod drain_filter; +mod extract_if; #[cfg(not(no_global_oom_handling))] #[stable(feature = "vec_splice", since = "1.21.0")] @@ -2892,7 +2892,7 @@ impl<T, A: Allocator> Vec<T, A> { /// If the closure returns false, the element will remain in the vector and will not be yielded /// by the iterator. /// - /// If the returned `DrainFilter` is not exhausted, e.g. because it is dropped without iterating + /// If the returned `ExtractIf` is not exhausted, e.g. because it is dropped without iterating /// or the iteration short-circuits, then the remaining elements will be retained. /// Use [`retain`] with a negated predicate if you do not need the returned iterator. /// @@ -2916,10 +2916,10 @@ impl<T, A: Allocator> Vec<T, A> { /// # assert_eq!(vec, vec![1, 4, 5]); /// ``` /// - /// But `drain_filter` is easier to use. `drain_filter` is also more efficient, + /// But `extract_if` is easier to use. `extract_if` is also more efficient, /// because it can backshift the elements of the array in bulk. /// - /// Note that `drain_filter` also lets you mutate every element in the filter closure, + /// Note that `extract_if` also lets you mutate every element in the filter closure, /// regardless of whether you choose to keep or remove it. /// /// # Examples @@ -2927,17 +2927,17 @@ impl<T, A: Allocator> Vec<T, A> { /// Splitting an array into evens and odds, reusing the original allocation: /// /// ``` - /// #![feature(drain_filter)] + /// #![feature(extract_if)] /// let mut numbers = vec![1, 2, 3, 4, 5, 6, 8, 9, 11, 13, 14, 15]; /// - /// let evens = numbers.drain_filter(|x| *x % 2 == 0).collect::<Vec<_>>(); + /// let evens = numbers.extract_if(|x| *x % 2 == 0).collect::<Vec<_>>(); /// let odds = numbers; /// /// assert_eq!(evens, vec![2, 4, 6, 8, 14]); /// assert_eq!(odds, vec![1, 3, 5, 9, 11, 13, 15]); /// ``` - #[unstable(feature = "drain_filter", reason = "recently added", issue = "43244")] - pub fn drain_filter<F>(&mut self, filter: F) -> DrainFilter<'_, T, F, A> + #[unstable(feature = "extract_if", reason = "recently added", issue = "43244")] + pub fn extract_if<F>(&mut self, filter: F) -> ExtractIf<'_, T, F, A> where F: FnMut(&mut T) -> bool, { @@ -2948,7 +2948,7 @@ impl<T, A: Allocator> Vec<T, A> { self.set_len(0); } - DrainFilter { vec: self, idx: 0, del: 0, old_len, pred: filter, panic_flag: false } + ExtractIf { vec: self, idx: 0, del: 0, old_len, pred: filter, panic_flag: false } } } |
