-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
retain
improvements
#2160
Comments
The deficiency of |
There's drain_filter on nightly which is very similar (except the condition is flipped). |
I think |
Now that https://doc.rust-lang.org/nightly/std/vec/struct.Vec.html#method.drain_filter is stable it seems that this is sufficiently fulfilled to close. |
Maybe I misunderstand what "stable" meant in this context, but ~1.5 years later it seems to be still unstable / nightly-only? |
Even if |
Firstly, I believe it would be sound for the function passed to
retain
to take a mutable reference instead of an immutable one. There is no real reason to restrict this. Additionally, I've found it useful to return the removed array as an&mut [T]
- since all the elements are at the end anyway this is essentially free. In my case I only allow this when the elements areCopy
(as a hack around not being able to specify!Drop
), but it would be sound to allowDrop
types. The issue is that it would unconditionally leak, which would be solved by an additional type that derefences to&mut [T]
but that drops its elements on drop. It would have to take a lifetime parameter to disallow mutating the vector after returning the elements.The text was updated successfully, but these errors were encountered: