Skip to content

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

Closed
wants to merge 1 commit into from

Conversation

chris-morgan
Copy link
Member

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.

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.
@chris-morgan
Copy link
Member Author

Of course, it rotted twenty minutes before I pushed… updated from pop_with to remove_with.

@chris-morgan chris-morgan changed the title Add a TreeMap.pop_with method. Add a TreeMap.remove_with method. Nov 7, 2014
@Gankra
Copy link
Contributor

Gankra commented Nov 7, 2014

I believe this is what the Borrow stuff in collections reform is supposed to deprecate. CC @aturon

@alexcrichton
Copy link
Member

I'm ok landing this for now as it's a nice-to-have, but if @aturon is close to landing the new Borrow trait then we may wish to hold off to not add a function and immediately deprecate it.

@chris-morgan
Copy link
Member Author

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).

@aturon
Copy link
Member

aturon commented Nov 8, 2014

@alexcrichton

I'm ok landing this for now as it's a nice-to-have, but if @aturon is close to landing the new Borrow trait then we may wish to hold off to not add a function and immediately deprecate it.

I plan to do this early next week.

@alexcrichton
Copy link
Member

Ok! @chris-morgan would you be ok holding out on this for a week? We definitely want to support this regardless!

@chris-morgan
Copy link
Member Author

Sure, I can hold on with no difficulty. My own use case only gains efficiency by doing this.

@Gankra
Copy link
Contributor

Gankra commented Nov 8, 2014

@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.

@Gankra
Copy link
Contributor

Gankra commented Nov 15, 2014

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.

@chris-morgan
Copy link
Member Author

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.

@alexcrichton
Copy link
Member

Ok, for now I think the Q: BorrowFrom bound will satisfy this particular request. We can look into investigating *_with later.

lnicola pushed a commit to lnicola/rust that referenced this pull request Dec 23, 2024
fix: remove `always!` check for file_id in `runnables`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants