-
Notifications
You must be signed in to change notification settings - Fork 13.3k
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
Clarify the difference between get_mut and into_mut for OccupiedEntry #49743
Clarify the difference between get_mut and into_mut for OccupiedEntry #49743
Conversation
The examples for both hash_map::OccupiedEntry::get_mut and hash_map::OccupiedEntry::into_mut were almost identical. This led to some confusion over the difference, namely why you would ever use get_mut when into_mut gives alonger lifetime. Reddit thread: https://www.reddit.com/r/rust/comments/8a5swr/why_does_hashmaps This commit adds two lines and a comment to the example, to show that the entry object can be re-used after calling get_mut.
r? @BurntSushi (rust_highfive has picked a reviewer for you, use r? to override) |
Is it worth perhaps explicitly calling out the difference between Thanks for taking the time to improve this. :-) |
Sure. I just don't know what to say exactly - there's a difference between giving a rough guesstimation of the difference on reddit and encoding information into the docs. |
(See also my separate but related issue #49745) |
Ping from triage! Can @BurntSushi (or someone else from @rust-lang/docs) review this PR? |
I'm okay with the changes as-is, though in my opinion, I think there's still room for a statement outside the doc example making a direct comparison between both methods. For example, for /// Gets a mutable reference to the value in the entry.
///
+ /// Unlike the [`into_mut`] method, `get_mut` should be used when you ______.
///
/// # Examples or /// Gets a mutable reference to the value in the entry.
///
+ /// If you need to ______ see the [`into_mut`] method.
///
/// # Examples The challenge here is succinctly filling in the Will think about this for a bit and maybe give other docs team members some time to respond. Will revisit in a few days and approve if there's not any other activity. |
Hum not much to say. Just wondering what @frewsxcv will find out. :D |
Ping from triage! What's the status of this PR? |
I'm going through stuff and haven't had the time to finish this yet. It's not forgotten, though. |
Ping from triage @Phlosioneer! Will you have time to work on this again in the future? |
I'm not confident with the wording of these, but: For
And for
Also if it's easy for you, please also make these changes to the |
Assigning to someone else from libs. r? @dtolnay |
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.
I agree with the review in #49743 (comment).
Ping from triage @Phlosioneer! It's been a while since we heard from you, will you have time to work on this again? |
In an attempt to keep this moving, I just opened a new pull request which cherry picks these two picks and adds in my suggested changes: #51312 . Hope that's alright @Phlosioneer! |
That's okay. I've been unable to devote time to rustc lately. |
The examples for both
hash_map::OccupiedEntry::get_mut
andhash_map::OccupiedEntry::into_mut
were almost identical. This ledto some confusion over the difference, namely why you would ever
use
get_mut
wheninto_mut
gives a longer lifetime. Reddit thread:https://www.reddit.com/r/rust/comments/8a5swr/why_does_hashmaps
This commit adds two lines and a comment to the example, to show
that the entry object can be re-used after calling
get_mut
.I'm open to alternate ways to modify these examples.