-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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::retain_mut and VecDeque::retain_mut #90829
Comments
Thank you! It's nice not to have to use a crate for this simple functionality. |
As I mentioned in #90772 (comment) maybe we should add this for VecDeque as well. |
I'll send a PR and we'll see if the libs team will agree or not. I'll update the issue afterward. |
…, r=m-ou-se Implement VecDeque::retain_mut Part of rust-lang#90829. In rust-lang#90772, someone suggested that `retain_mut` should also be implemented on `VecDeque`. I think that it follows the same logic (coherency). So first: is it ok? Second: should I create a new feature for it or can we put it into the same one? r? `@joshtriplett`
121: Make sure the `RetainMut::retain_mut` method is effectively used r=Kerollmops a=Kerollmops This PR uses the fully qualified syntax to make sure that we use the `retain_mut` trait method of the `RetainMut` trait and not the one from the `vec_retain_mut` nighty feature [that will be added to the standard library](rust-lang/rust#90829) soon. Co-authored-by: Clément Renault <clement@meilisearch.com>
This is pretty neat. if anyone else is looking then it seems that the current best stable alternative is: |
Should we start an FCP to stabilize it? |
@rfcbot merge |
Team member @m-ou-se 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. |
To be clear, I was not suggesting that retain_mut should be delayed in favor of drain_filter, but that it seems annoying that the current implementations result in a flipped conditional -- if you are refactoring and start to need the elements returned from retain_mut, and are now using drain_filter, then you need to be careful to flip the return value of your closure. I suppose this is more of an argument to change drain_filter than retain_mut, since retain_mut should match retain for sure, though. |
From this zulip thread: There are two ways
The latter might also obviate some needs for |
I don't think either of those should be the job of retain_mut. retain_mut should behave exactly as retain, with the only exception of taking &mut. |
Obviously the method could be renamed if it does more.
If the performance is the same I don't see much of a benefit of having both. |
The benefit is to have it now. It's a simple fix to a mistake. It doesn't bloat the standard library in any significant way. This has been missing for years because other alternatives keep getting bikeshedded. |
Considering that things that go into std have to be maintained forever rushing things doesn't seem like a good plan either. |
There is nothing to maintain to speak of. retain is already well established. retain_mut is the exact same function with changed mutability |
Tests, documentation and general clutter in the API surface have non-zero costs. Anyway, I don't see urgency here and I would prefer not to spend more time on meta-discussion and instead discuss the API itself on its own merits rather than shutting down discussion on the ground that discussion is harmful because it delays things. So, back to the API itself. Taking As far as complexity for users goes I think |
I argue that it qualifies as a fix rather than simply a generalization. There is no reason why it shouldn't take &mut T, so taking &T was a mistake. The merit of this change is to fix that mistake (without breaking backwards compatibility). If a more general API is possible, it would deprecate |
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. |
I submitted a stabilization PR. #95491. Looks like that's the only remaining thing here. And I would appreciate if this made it into 1.61 |
I'm concerned that there was a fair bit of discussion and new comments on this issue during the FCP and I want to be careful to review the comments so far to make sure that none of them should be promoted to a blocking concern before I go ahead and approve the stabilization PR. I'll do that as soon as I'm done with the libs teams meetings in a little over an hour. Edit: So my summary of the recent discussion is that there was some more discussion related to drain filter, that bled over into retain_mut. The main concerns raised were around:
I don't think the API bloat concern is particularly specific to this issue, and any more powerful API would not necessarily solve the issue in this case since we would still be left with |
Apologies if this is not the appropriate place to ask this. I'd like to be able to call edit: looks like I want Keyword Generics. |
121: Make sure the `RetainMut::retain_mut` method is effectively used r=Kerollmops a=Kerollmops This PR uses the fully qualified syntax to make sure that we use the `retain_mut` trait method of the `RetainMut` trait and not the one from the `vec_retain_mut` nighty feature [that will be added to the standard library](rust-lang/rust#90829) soon. Co-authored-by: Clément Renault <clement@meilisearch.com>
║ error[E0658]: use of unstable library feature 'vec_retain_mut' ║ --> /cargo-home/git/checkouts/substrate-7e08433d4c370a21/34a0621/client/transaction-pool/src/graph/validated_pool.rs:207:12 ║ | ║ 207 | sinks.retain_mut(|sink| match sink.try_send(*hash) { ║ | ^^^^^^^^^^ ║ | ║ = note: see issue #90829 <rust-lang/rust#90829> for more information ║ = help: add `#![feature(vec_retain_mut)]` to the crate attributes to enable
* fix: attempt to fix srtool build issue ║ error[E0658]: use of unstable library feature 'vec_retain_mut' ║ --> /cargo-home/git/checkouts/substrate-7e08433d4c370a21/34a0621/client/transaction-pool/src/graph/validated_pool.rs:207:12 ║ | ║ 207 | sinks.retain_mut(|sink| match sink.try_send(*hash) { ║ | ^^^^^^^^^^ ║ | ║ = note: see issue #90829 <rust-lang/rust#90829> for more information ║ = help: add `#![feature(vec_retain_mut)]` to the crate attributes to enable
Pin tokio to 1.29.0 since it requires socket2 v0.5.3 which requires rust 1.63 Also `cargo update -p cc --precise 1.0.81` due to rust-lang/rust#90829
Pin tokio to 1.29.0 since it requires socket2 v0.5.3 which requires rust 1.63 Pin cc to 1.0.81 due to rust-lang/rust#90829
Pin tokio to 1.29.0 since it requires socket2 v0.5.3 which requires rust 1.63 Pin cc to 1.0.81 due to rust-lang/rust#90829
Pin tokio to 1.29.0 since it requires socket2 v0.5.3 which requires rust 1.63 Pin cc to 1.0.81 due to rust-lang/rust#90829
* fix: attempt to fix srtool build issue ║ error[E0658]: use of unstable library feature 'vec_retain_mut' ║ --> /cargo-home/git/checkouts/substrate-7e08433d4c370a21/34a0621/client/transaction-pool/src/graph/validated_pool.rs:207:12 ║ | ║ 207 | sinks.retain_mut(|sink| match sink.try_send(*hash) { ║ | ^^^^^^^^^^ ║ | ║ = note: see issue #90829 <rust-lang/rust#90829> for more information ║ = help: add `#![feature(vec_retain_mut)]` to the crate attributes to enable
Feature gate:
#![feature(vec_retain_mut)]
This is a tracking issue for adding the
retain_mut
method onVec
.It'll provide a
retain_mut
method on theVec
and on theVecDeque
types. It is the equivalent of theVec::retain
andVecDeque
methods except that it'll expect a closure with a mutable argument instead of a const one. It'll allow to modify the elements of an array while filtering which elements we want to keep.Public API
Steps / History
Unresolved Questions
None
The text was updated successfully, but these errors were encountered: