-
Notifications
You must be signed in to change notification settings - Fork 51
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
Add retain_mut #198
Add retain_mut #198
Conversation
This adds a `retain_mut` method to `ArrayVec` and `TinyVec` that's just `retain` but with mutable references. This method is present on `std::vec::Vec` as of a while ago so it's nice to have in `tinyvec` too. Fixes Lokathor#195
The implementation is just copy-pasted |
I guess this fails on 1.47 because retain_mut on std::vec::Vec wasn't present yet. I'm not sure how to deal with it. The options are:
Seems Vec::retain_mut appeared in 1.61.0 according to https://github.com/rust-lang/rust/blob/master/RELEASES.md#version-1610-2022-05-19 (2 years ago!) I guess I'd lean towards the third option? |
I had a look at Cargo.toml, seems there's:
So perhaps we add |
I guess 4th option is to only add retain_mut to ArrayVec as that's manually implemented and not add it to TinyVec but that's sad. |
Adding |
It calls `std::vec::Vec::retain_mut` which is only available since Rust 1.61. People that still want to use a very old compiler (CI seems to use 1.47) still get to compile the crate, they just don't get `TinyVec::retain_mut`. Note that `ArrayVec::retain_mut` is implemented inside the crate so it's still available, just the `TinyVec` format is not.
@Lokathor Thanks, I added a commit that adds the feature. Not sure if I have to change something else, like docs features etc. Let me know if I have to change something. |
This seems to pass CI now at least. Can you add some test cases for this new method? The TinyVec method just calls the version in ArrayVec or Vec, but the new ArrayVec code should have some test cases. |
I've added some tests. Technically it was tested already as much as |
released in |
This adds a
retain_mut
method toArrayVec
andTinyVec
that's justretain
but with mutablereferences. This method is present on
std::vec::Vec
as of a while ago so it's nice tohave in
tinyvec
too.Fixes #195