Skip to content

Implement get_pair for HashMap - #46992

Closed
Diggsey wants to merge 2 commits into
rust-lang:masterfrom
Diggsey:hashmap-get-pair
Closed

Implement get_pair for HashMap#46992
Diggsey wants to merge 2 commits into
rust-lang:masterfrom
Diggsey:hashmap-get-pair

Conversation

@Diggsey

Copy link
Copy Markdown
Contributor

Fixes#43143

@rust-highfive

Copy link
Copy Markdown
Contributor

r? @Kimundi

(rust_highfive has picked a reviewer for you, use r? to override)

@ghost

Copy link
Copy Markdown

Any reason for not adding the same method to BTreeMap?

@Diggsey

Copy link
Copy Markdown
ContributorAuthor

No, it just wasn't mentioned in the issue - I will add it there too.

@nvzqz

Copy link
Copy Markdown
Contributor

Is it possible to have get_pair_mut that returns Option<(&K, &mut V)>?

@Diggsey

Copy link
Copy Markdown
ContributorAuthor

@nvzqz The entry api covers that case

@nvzqz

Copy link
Copy Markdown
Contributor

The entry api requires passing an owned key (K) whereas this allows passing any Q where K: Borrow<Q>.

@kennytmkennytm added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs-api [DEPRECATED; DO NOT USE] labels Dec 27, 2017
@alexcrichton

Copy link
Copy Markdown
Member

ping @rust-lang/libs, thoughts on this API/naming?

@alexcrichtonalexcrichton added S-waiting-on-team and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jan 4, 2018
@sfackler

Copy link
Copy Markdown
Member

#47259 added HashMap::remove_entry - the namings for the remove and access should hopefully match. get_entry may be confusing though in comparison to entry?

@RReverser

Copy link
Copy Markdown
Contributor

I'll back get_pair_mut suggestion, but even without it this addition looks pretty good.

@RReverser

RReverser commented Jan 18, 2018

Copy link
Copy Markdown
Contributor

Although get_pair_mut could instead be occupied_entry(&mut self, &K) -> Option<OccupiedEntry> instead to provide all the convenient mutation APIs for free, so probably unrelated to this PR.

@carols10centscarols10cents added I-nominated I-needs-decision Issue: In need of a decision. labels Jan 22, 2018
@Diggsey

Copy link
Copy Markdown
ContributorAuthor

I've added the BTreeMap method too. I'm not going to add the mutable versions as part of this PR as I think there are still some questions about what the API should look like.

@aturonaturon assigned aturon and unassigned KimundiFeb 6, 2018
@aturon

Copy link
Copy Markdown
Contributor

Sorry for the delay on this from the libs team!

I think that get_entry is too confusing, as @sfackler mentioned, but get_pair is not very self-explanatory.

How about get_key_value?

@emilyalbiniemilyalbini added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed I-needs-decision Issue: In need of a decision. I-nominated labels Feb 19, 2018
@emilyalbini

Copy link
Copy Markdown
Member

@Diggsey someone from the libs team replied with a suggestion for another name, can you implement that?

@emilyalbini

Copy link
Copy Markdown
Member

@Diggsey thanks for taking the time to send this PR! Unfortunately, there was no activity for more than two weeks, so I'm closing it. If you have time to work on it again, feel free to open another PR with the new changes, we'll be happy to review and merge it!

kennytm added a commit to kennytm/rust that referenced this pull request Mar 26, 2018
…mulacrum
Implement get_key_value for HashMap, BTreeMap
Fixesrust-lang#43143
Follow up from rust-lang#46992
TimNN added a commit to TimNN/rust that referenced this pull request Mar 26, 2018
…mulacrum
Implement get_key_value for HashMap, BTreeMap
Fixesrust-lang#43143
Follow up from rust-lang#46992
RReverser added a commit to cloudflare/wirefilter that referenced this pull request Feb 20, 2019
We won't need this when rust-lang/rust#46992 is implemented, but for now this is the easiest (and safe) way to untie Filter AST from its string representation, so it can live as long as the context does.
RReverser added a commit to cloudflare/wirefilter that referenced this pull request Feb 20, 2019
We won't need this when rust-lang/rust#46992 is implemented, but for now this is the easiest (and safe) way to untie Filter AST from its string representation, so it can live as long as the context does.
RReverser added a commit to cloudflare/wirefilter that referenced this pull request Feb 20, 2019
We won't need this when rust-lang/rust#46992 is implemented, but for now this is the easiest (and safe) way to untie Filter AST from its string representation, so it can live as long as the context does.
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-authorStatus: This is awaiting some action (such as code changes or more information) from the author.T-libs-api[DEPRECATED; DO NOT USE]

Projects

None yet

Development

Successfully merging this pull request may close these issues.

11 participants

@Diggsey@rust-highfive@nvzqz@alexcrichton@sfackler@RReverser@aturon@emilyalbini@kennytm@carols10cents@Kimundi