Skip to content

Please add find_equiv to TreeMap #14549

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Closed
SimonSapin opened this issue May 31, 2014 · 3 comments
Closed

Please add find_equiv to TreeMap #14549

SimonSapin opened this issue May 31, 2014 · 3 comments

Comments

@SimonSapin
Copy link
Contributor

For accessing a key in a JSON object (which is represented in memory as TreeMap<String, Json>), I find myself writing code like map.find(&key.to_string()) that really should be just map.find(key).

HashMap has a find_equiv method to do this. It’d be nice to have it in TreeMap. (Other convenience method may apply to.)

However, you may want to block this on a decision from #12135.

@thestinger
Copy link
Contributor

It's not possible to use Equiv for TreeMap. TreeMap needs TotalOrd rather than just an equivalent to Eq. I think Equiv a poor solution to this issue and a method taking a closure would be a lot more sensible (likely for HashMap too).

@thestinger
Copy link
Contributor

I came up with a working way to convert &[T] -> &String and &[T] -> &Vec<T> so it should solve this for the common cases. It looks like map.find(&*as_string(slice)) at the moment. There is already a find_with method on TreeMap for the general case.

@thestinger
Copy link
Contributor

(not possible)

bors added a commit to rust-lang-ci/rust that referenced this issue Jun 5, 2023
…stable, r=Veykril

Don't suggest unstable items on stable toolchain

Closes rust-lang#3020

This PR implements stability check in `ide-completion` so that unstable items are only suggested if you're on nightly toolchain.

It's a bit unfortunate `CompletionContext::check_stability()` is spammed all over the crate, but we should call it before building `CompletionItem` as you cannot get attributes on the item it's completing from that struct. I looked up every callsite of `Builder::add_to()`, `Completions::add[_opt]()`, and`Completions::add_all()` and inserted the check wherever necessary.

The tests are admittedly incomplete in that I didn't add tests for every kind of item as I thought that would be too big and not worthwhile. I copy-pasted some existing basic tests in every test module and adjusted them.
bors added a commit to rust-lang-ci/rust that referenced this issue Jun 5, 2023
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants