-
Notifications
You must be signed in to change notification settings - Fork 13.2k
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
Tracking Issue for Vec::pop_if
#122741
Comments
Implement `Vec::pop_if` This PR adds `Vec::pop_if` to the public API, behind the `vec_pop_if` feature. ```rust impl<T> Vec<T> { pub fn pop_if<F>(&mut self, f: F) -> Option<T> where F: FnOnce(&mut T) -> bool; } ``` Tracking issue: rust-lang#122741 ## Open questions - [ ] Should the first unit test be split up? - [ ] I don't see any guidance on ordering of methods in impl blocks, should I move the method elsewhere?
Rollup merge of rust-lang#123107 - avandesa:vec_pop_if, r=joboet Implement `Vec::pop_if` This PR adds `Vec::pop_if` to the public API, behind the `vec_pop_if` feature. ```rust impl<T> Vec<T> { pub fn pop_if<F>(&mut self, f: F) -> Option<T> where F: FnOnce(&mut T) -> bool; } ``` Tracking issue: rust-lang#122741 ## Open questions - [ ] Should the first unit test be split up? - [ ] I don't see any guidance on ordering of methods in impl blocks, should I move the method elsewhere?
Found a piece of code in the wild that could benefit (get rid of an Also I myself have found this feature to be useful on couple occasions in personal projects. This does not look too controversial, so maybe let's stabilize it? The corresponding I don't think I have right to start an FCP, so I will just open a PR instead. |
Docs should probably mention that the function does not get run if the vector is empty.
You can add the I-libs-api-nominated label with rustbot |
Thanks, that makes sense @rustbot label +I-libs-api-nominated
True, it might have side-effects, so it's probably worth mentioning. I will adjust my PR. |
@rfcbot merge |
Team member @Amanieu has proposed to merge this. The next step is review by the rest of the tagged team members: No concerns currently listed. Once a majority of reviewers approve (and at most 2 approvals are outstanding), this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up! See this document for info about what commands tagged team members can give me. |
Is there a reason why we use Should I change this from impl<T> Vec<T> {
pub fn pop_if<F>(&mut self, f: F) -> Option<T>
where F: FnOnce(&mut T) -> bool;
} to impl<T> Vec<T> {
pub fn pop_if(&mut self, predicate: impl FnOnce(&mut T) -> bool) -> Option<T>;
} in stabilization PR (#135488)? |
Yes, please do. It's always backwards-compatible to change an |
Done |
This is not true: Such a change breaks call/usage sites where the generic argument list is specified (aka turbofished call/usage sites). However, in the case of |
🔔 This is now entering its final comment period, as per the review above. 🔔 |
The final comment period, with a disposition to merge, as per the review above, is now complete. As the automated representative of the governance process, I would like to thank the author for their work and everyone else who contributed. This will be merged soon. |
Stabilize `vec_pop_if` Tracking issue: rust-lang#122741 FCP completed in rust-lang#122741 (comment)
Stabilize `vec_pop_if` Tracking issue: rust-lang#122741 FCP completed in rust-lang#122741 (comment)
Rollup merge of rust-lang#135488 - GrigorenkoPV:vec_pop_if, r=jhpratt Stabilize `vec_pop_if` Tracking issue: rust-lang#122741 FCP completed in rust-lang#122741 (comment)
Stabilize `vec_pop_if` Tracking issue: rust-lang#122741 FCP completed in rust-lang#122741 (comment)
Stabilize `vec_pop_if` Tracking issue: rust-lang#122741 FCP completed in rust-lang#122741 (comment)
Feature gate:
#![feature(vec_pop_if)]
This feature adds the
Vec::pop_if
method, which takes a predicate, evaluates it with the last element in theVec
if present, and returns the item if the predicate returnstrue
. This makes it possible to conditionally remove the last element without the use ofunwrap
.Public API
Steps / History
pop_if
orEntry
/Peek
-like API forVec
andVecDeque
libs-team#208Vec::pop_if
#123107Unresolved Questions
VecDeque::pop_front_if
andVecDeque::pop_back_if
API under this as well?VecDeque::pop_front_if
&VecDeque::pop_back_if
#135889Footnotes
https://std-dev-guide.rust-lang.org/feature-lifecycle/stabilization.html ↩
The text was updated successfully, but these errors were encountered: