-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Addressed issues raised in #44286. (OccupiedEntry::replace_entry
)
#45152
Conversation
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @dtolnay (or someone else) soon. If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes. Please see the contribution instructions for more information. |
OccupiedEntry::replace_entry
)
src/libstd/collections/hash/map.rs
Outdated
#[unstable(feature = "map_entry_replace", issue = "44286")] | ||
pub fn replace_key(mut self) -> K { | ||
let (old_key, _) = self.elem.read_mut(); | ||
mem::replace(old_key, self.key.unwrap()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please change the tabs into spaces.
[00:04:04] tidy error: /checkout/src/libstd/collections/hash/map.rs:2289: tab character
[00:04:04] tidy error: /checkout/src/libstd/collections/hash/map.rs:2290: tab character
Ping @dtolnay for review! (also pinged on IRC) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the reminder!
I am on board with the idea, and the implementation looks good. But could you change the usage example to illustrate a more realistic use case? Replacing "poneyland".to_string() with "poneyland".to_string() is not meaningful.
In general, usage examples are often not about how to use a particular API. If the user got far enough with Rust to be looking at OccupiedEntry documentation, we can assume they understand how to match on an enum and invoke functions. Here and elsewhere, the role of the example should be about why someone would want this functionality.
Either here or in a following PR, please also update the replace_entry documentation with a why example.
@dtolnay @carols10cents Oh, whoops. I missed this one. It sure does. As for Discussion: #44286 |
It can be used for example to reclaim memory used by keys. E. g.
|
Triage ping @Binero! It looks like you got some feedback on the rationale for |
This commit renames the `replace` function to `replace_entry`, and creates a seperate `replace_key` function for `OccupiedEntry`. The original `replace` function did not solve the use-case where the key needed to be replaced, but not the value. Documentation and naming has also been updated to better reflect what the original replace function does.
Added better examples, and rebased them all. |
@bors r+ |
📌 Commit 3ba2631 has been approved by |
⌛ Testing commit 3ba26319996e3d1d8a6594a80e3ab0acb89ade66 with merge 5120f57e5210955682db123cfb4a23d12143f80e... |
💔 Test failed - status-appveyor |
|
The current examples should be more realistic.
Amended the style-changes to the last commit. |
@bors r+ |
📌 Commit 0fb37fc has been approved by |
Addressed issues raised in #44286. (`OccupiedEntry::replace_entry`) This commit renames the `replace` function to `replace_entry`, and creates a seperate `replace_key` function for `OccupiedEntry`. The original `replace` function did not solve the use-case where the key needed to be replaced, but not the value. Documentation and naming has also been updated to better reflect what the original replace function does.
☀️ Test successful - status-appveyor, status-travis |
Closes rust-lang#27078. Closes rust-lang#27985. Closes rust-lang#39848. Closes rust-lang#42164. Closes rust-lang#42479. Closes rust-lang#45152. Closes rust-lang#45662. Closes rust-lang#45876. Closes rust-lang#45965.
This commit renames the
replace
function toreplace_entry
, andcreates a seperate
replace_key
function forOccupiedEntry
. Theoriginal
replace
function did not solve the use-case where thekey needed to be replaced, but not the value. Documentation and
naming has also been updated to better reflect what the original
replace function does.