Skip to content
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

Stabilize or_insert_with_key #78083

Merged
merged 4 commits into from
Dec 19, 2020
Merged

Stabilize or_insert_with_key #78083

merged 4 commits into from
Dec 19, 2020

Conversation

ChaiTRex
Copy link
Contributor

Stabilizes the or_insert_with_key feature from #71024. This allows inserting key-derived values when a HashMap/BTreeMap entry is vacant.

The difference between this and .or_insert_with(|| ... ) is that this provides a reference to the key to the closure after it is moved with .entry(key_being_moved), avoiding the need to copy or clone the key.

@rust-highfive
Copy link
Collaborator

r? @varkor

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

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Oct 18, 2020
@jonas-schievink jonas-schievink added A-collections Area: `std::collection` needs-fcp This change is insta-stable, so needs a completed FCP to proceed. relnotes Marks issues that should be documented in the release notes of the next release. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. labels Oct 18, 2020
@varkor
Copy link
Member

varkor commented Oct 21, 2020

This will needs a libs team sign-off.

r? @SimonSapin

@rust-highfive rust-highfive assigned SimonSapin and unassigned varkor Oct 21, 2020
@crlf0710 crlf0710 added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Nov 7, 2020
@m-ou-se
Copy link
Member

m-ou-se commented Nov 25, 2020

@rfcbot merge

@rfcbot
Copy link

rfcbot commented Nov 25, 2020

Team member @m-ou-se has proposed to merge this. The next step is review by the rest of the tagged team members:

No concerns currently listed.

Once a majority of reviewers approve (and at most 2 approvals are outstanding), this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up!

See this document for info about what commands tagged team members can give me.

@rfcbot rfcbot added proposed-final-comment-period Proposed to merge/close by relevant subteam, see T-<team> label. Will enter FCP once signed off. disposition-merge This issue / PR is in PFCP or FCP with a disposition to merge it. labels Nov 25, 2020
@m-ou-se
Copy link
Member

m-ou-se commented Nov 25, 2020

Sorry for the delay! Unfortunately this missed 1.49. Can you update the stable versions to 1.50?

@ChaiTRex
Copy link
Contributor Author

ChaiTRex commented Dec 1, 2020

@m-ou-se It is updated in the latest commit.

@BurntSushi
Copy link
Member

The difference between this and .or_insert_with(|| ... ) is that this provides a reference to the key to the closure after it is moved with .entry(key_being_moved), avoiding the need to copy or clone the key.

This seems like a useful bit of information that would be good to add to the docs.

@ChaiTRex
Copy link
Contributor Author

ChaiTRex commented Dec 7, 2020

@BurntSushi How about this?

Ensures a value is in the entry by inserting, if empty, the result of the default function. This method allows for generating key-derived values for insertion by providing the default function a reference to the key that was moved during the .entry(key) method call.

The reference to the moved key is provided so that cloning or copying the key is unnecessary, unlike with .or_insert_with(|| ... ).

@BurntSushi
Copy link
Member

@ChaiTRex Thank you, that looks great to me!

@rfcbot rfcbot added the final-comment-period In the final comment period and will be merged soon unless new substantive objections are raised. label Dec 8, 2020
@rfcbot
Copy link

rfcbot commented Dec 8, 2020

🔔 This is now entering its final comment period, as per the review above. 🔔

@rfcbot rfcbot removed the proposed-final-comment-period Proposed to merge/close by relevant subteam, see T-<team> label. Will enter FCP once signed off. label Dec 8, 2020
@rfcbot rfcbot added the finished-final-comment-period The final comment period is finished for this PR / Issue. label Dec 18, 2020
@rfcbot
Copy link

rfcbot commented Dec 18, 2020

The final comment period, with a disposition to merge, as per the review above, is now complete.

As the automated representative of the governance process, I would like to thank the author for their work and everyone else who contributed.

The RFC will be merged soon.

@rfcbot rfcbot added to-announce Announce this issue on triage meeting and removed final-comment-period In the final comment period and will be merged soon unless new substantive objections are raised. labels Dec 18, 2020
@m-ou-se
Copy link
Member

m-ou-se commented Dec 18, 2020

@bors r+ rollup

@bors
Copy link
Contributor

bors commented Dec 18, 2020

📌 Commit f115be9 has been approved by m-ou-se

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Dec 18, 2020
Dylan-DPC-zz pushed a commit to Dylan-DPC-zz/rust that referenced this pull request Dec 19, 2020
Stabilize or_insert_with_key

Stabilizes the `or_insert_with_key` feature from rust-lang#71024. This allows inserting key-derived values when a `HashMap`/`BTreeMap` entry is vacant.

The difference between this and  `.or_insert_with(|| ... )` is that this provides a reference to the key to the closure after it is moved with `.entry(key_being_moved)`, avoiding the need to copy or clone the key.
bors added a commit to rust-lang-ci/rust that referenced this pull request Dec 19, 2020
Rollup of 7 pull requests

Successful merges:

 - rust-lang#78083 (Stabilize or_insert_with_key)
 - rust-lang#79211 (Add the "async" and "promise" doc aliases to `core::future::Future`)
 - rust-lang#79612 (Switch some links in compiler/ to intra-doc links)
 - rust-lang#80068 (Add `&mut` as an alias for 'reference' primitive)
 - rust-lang#80129 (docs: Edit rustc_ast::token::Token)
 - rust-lang#80133 (Suppress `CONST_ITEM_MUTATION` lint if a dereference occurs anywhere)
 - rust-lang#80155 (Fix typo)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 0765536 into rust-lang:master Dec 19, 2020
@rustbot rustbot added this to the 1.50.0 milestone Dec 19, 2020
@spastorino spastorino removed the to-announce Announce this issue on triage meeting label Dec 31, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-collections Area: `std::collection` disposition-merge This issue / PR is in PFCP or FCP with a disposition to merge it. finished-final-comment-period The final comment period is finished for this PR / Issue. needs-fcp This change is insta-stable, so needs a completed FCP to proceed. relnotes Marks issues that should be documented in the release notes of the next release. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.