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

Add or_insert_with_key to Entry of HashMap #152

Merged
merged 1 commit into from
Apr 11, 2020
Merged

Add or_insert_with_key to Entry of HashMap #152

merged 1 commit into from
Apr 11, 2020

Conversation

ChaiTRex
Copy link
Contributor

Going along with or_insert_with, or_insert_with_key provides the Entry's key to the lambda, avoiding the need to either clone the key or the need to reimplement this body of this method from scratch each time.

This is useful when the initial value for a map entry is derived from the key. For example, the introductory Rust book has an example Cacher struct that takes an expensive-to-compute lambda and then can, given an argument to the lambda, produce either the cached result or execute the lambda.


This is modified from rust-lang/rust#70996 and intended to sync the APIs of std and hashbrown.

Going along with or_insert_with, or_insert_with_key provides the
Entry's key to the lambda, avoiding the need to either clone the
key or the need to reimplement this body of this method from
scratch each time.

This is useful when the initial value for a map entry is derived
from the key. For example, the introductory Rust book has an
example Cacher struct that takes an expensive-to-compute lambda and
then can, given an argument to the lambda, produce either the
cached result or execute the lambda.

This is modified from rust-lang/rust#70996.
@Amanieu
Copy link
Member

Amanieu commented Apr 11, 2020

@bors r+

@bors
Copy link
Contributor

bors commented Apr 11, 2020

📌 Commit fa0a4db has been approved by Amanieu

bors added a commit that referenced this pull request Apr 11, 2020
Add or_insert_with_key to Entry of HashMap

Going along with `or_insert_with`, `or_insert_with_key` provides the `Entry`'s key to the lambda, avoiding the need to either clone the key or the need to reimplement this body of this method from scratch each time.

This is useful when the initial value for a map entry is derived from the key. For example, the introductory Rust book has an example Cacher struct that takes an expensive-to-compute lambda and then can, given an argument to the lambda, produce either the cached result or execute the lambda.

---

This is modified from rust-lang/rust#70996 and intended to sync the APIs of `std` and `hashbrown`.
@bors
Copy link
Contributor

bors commented Apr 11, 2020

⌛ Testing commit fa0a4db with merge c16c44a...

@bors
Copy link
Contributor

bors commented Apr 11, 2020

💥 Test timed out

@Amanieu
Copy link
Member

Amanieu commented Apr 11, 2020

@bors retry

@bors
Copy link
Contributor

bors commented Apr 11, 2020

⌛ Testing commit fa0a4db with merge 7f72e0c...

bors added a commit that referenced this pull request Apr 11, 2020
Add or_insert_with_key to Entry of HashMap

Going along with `or_insert_with`, `or_insert_with_key` provides the `Entry`'s key to the lambda, avoiding the need to either clone the key or the need to reimplement this body of this method from scratch each time.

This is useful when the initial value for a map entry is derived from the key. For example, the introductory Rust book has an example Cacher struct that takes an expensive-to-compute lambda and then can, given an argument to the lambda, produce either the cached result or execute the lambda.

---

This is modified from rust-lang/rust#70996 and intended to sync the APIs of `std` and `hashbrown`.
@bors
Copy link
Contributor

bors commented Apr 11, 2020

💥 Test timed out

@Amanieu
Copy link
Member

Amanieu commented Apr 11, 2020

@bors retry

@bors
Copy link
Contributor

bors commented Apr 11, 2020

⌛ Testing commit fa0a4db with merge d2414e4...

@bors
Copy link
Contributor

bors commented Apr 11, 2020

☀️ Test successful - checks-travis
Approved by: Amanieu
Pushing d2414e4 to master...

@bors bors merged commit d2414e4 into rust-lang:master Apr 11, 2020
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.

3 participants