-
Notifications
You must be signed in to change notification settings - Fork 13.5k
Add a TreeMap.remove_with
method.
#18727
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
Conversation
TreeMap has methods `find`, `find_mut` and `remove`, which take `&K` and return `Option` of `&V`, `&mut V` and `V`; and `find_with` and `find_with_mut` which take `|&K| -> Ordering`, but `remove_with` was missing from this symmetry.
10205f9
to
ea6057f
Compare
Of course, it rotted twenty minutes before I pushed… updated from |
TreeMap.pop_with
method.TreeMap.remove_with
method.
I believe this is what the Borrow stuff in collections reform is supposed to deprecate. CC @aturon |
I'm ok landing this for now as it's a nice-to-have, but if @aturon is close to landing the new |
I just want something that can achieve this general goal for my JSON Pointer implementation so that I can avoid allocations entirely; I don’t mind what it is, and until it comes I can just do it a less efficient way (produce the actual String and call pop). |
I plan to do this early next week. |
Ok! @chris-morgan would you be ok holding out on this for a week? We definitely want to support this regardless! |
Sure, I can hold on with no difficulty. My own use case only gains efficiency by doing this. |
@alexcrichton This trivially falls out of collection reform's design, if I recall correctly. The K taken by get and remove is of type Borrow. As such I think we can close this PR altogether. Although honestly I'm a bit fuzzy on exactly which of the few different forms of Borrow @aturon ultimately settled on, it's 2am, and I don't have the energy to pore over the whole RFC again. Regardless, if the proposed design handles find_with, remove_with should fall out trivially. |
Looks like current design is punting on supporting the full _with usecase at the moment. There's some ideas to handle it, but the rest of the libraries/compiler aren't there yet. I suppose this should be merged, as an #[experimental] shim, then. |
Yes, it’s not doing quite everything this can, but the main reason one would want this is taken care of. I don’t care about this any more. |
Ok, for now I think the |
fix: remove `always!` check for file_id in `runnables`
TreeMap has methods
find
,find_mut
andremove
, which take&K
andreturn
Option
of&V
,&mut V
andV
; andfind_with
andfind_with_mut
which take|&K| -> Ordering
, butremove_with
wasmissing from this symmetry.