-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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 HashMap Entry enums examples #34935
Conversation
Looks good to me! |
1d033ea
to
04c032d
Compare
@bors: r+ rollup |
📌 Commit 04c032d has been approved by |
/// let mut map: HashMap<&str, usize> = HashMap::new(); | ||
/// map.entry("poneyland").or_insert(12); | ||
/// | ||
/// assert_eq!(map["poneyland"], 12); |
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.
You could just assert against the reference or_insert
returns.
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 don't agree with you. This way, it's very clear that the value has been correctly set to this key. I can add an assert_eq!
to check the returned value of or_insert
but I don't think removing the current one is a good idea.
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.
Note, that then this example does not demonstrate how the or_insert()
returns a mutable reference which can be inspected and written to.
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.
Ok, now I see your point and indeed, it would be better. I'll add a second example to demonstrate the mutable reference.
@bors: r- |
04c032d
to
cabb32e
Compare
Updated. |
cabb32e
to
ec33dab
Compare
Updated. |
@bors: r+ rollup |
📌 Commit ec33dab has been approved by |
…eklabnik Add HashMap Entry enums examples Part of rust-lang#29348. r? @steveklabnik
⌛ Testing commit ec33dab with merge 1974e04... |
💔 Test failed - auto-win-msvc-64-opt |
@bors: retry On Tue, Jul 26, 2016 at 4:18 AM, bors notifications@github.com wrote:
|
…eklabnik Add HashMap Entry enums examples Part of rust-lang#29348. r? @steveklabnik
Part of #29348.
r? @steveklabnik