-
Notifications
You must be signed in to change notification settings - Fork 13.1k
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
Implement Vec::pop_if
#123107
Implement Vec::pop_if
#123107
Conversation
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @joboet (or someone else) some time within the next two weeks. Please see the contribution instructions for more information. Namely, in order to ensure the minimum review times lag, PR authors and assigned reviewers should ensure that the review label (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the predicate modifies the value but returns false
, that should be reflected in the vector. Hence this should call f
with the value still in the vector, and only then remove it. Also, I'd prefer if this didn't use unsafe
, I'd wager that the optimizer is able to deal with a combination of slice::last
and Vec::pop
just fine.
Fair enough, I'll trust your judgement on the optimizer. Switch to @rustbot review |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great, thank you very much! Could you squash the commits, please?
Then r=me
(this shorthand tells other people with merge rights that they can merge this on my behalf if don't get to it right away)
@bors r=joboet |
@avandesa: 🔑 Insufficient privileges: Not in reviewers |
Ope, I misunderstood that I think |
@bors r=joboet |
…iaskrgr Rollup of 7 pull requests Successful merges: - rust-lang#122439 (match lowering: build the `Place` instead of keeping a `PlaceBuilder` around) - rust-lang#122880 (Unix: Support more platforms with `preadv` and `pwritev`) - rust-lang#123038 (std library thread.rs: fix NetBSD code for ILP32 CPUs.) - rust-lang#123084 (`UnixStream`: override `read_buf`) - rust-lang#123102 (RustWrapper: update call for llvm/llvm-project@44d037cc258dcf179d2c48…) - rust-lang#123107 (Implement `Vec::pop_if`) - rust-lang#123118 (Update `RwLock` deadlock example to not use shadowing) r? `@ghost` `@rustbot` modify labels: rollup
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?
This PR adds
Vec::pop_if
to the public API, behind thevec_pop_if
feature.Tracking issue: #122741
Open questions