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 HashMap Entry enums examples #34935

Merged
merged 1 commit into from
Jul 27, 2016
Merged

Conversation

GuillaumeGomez
Copy link
Member

Part of #29348.

r? @steveklabnik

@frewsxcv
Copy link
Member

Looks good to me!

@steveklabnik
Copy link
Member

@bors: r+ rollup

@bors
Copy link
Contributor

bors commented Jul 20, 2016

📌 Commit 04c032d has been approved by steveklabnik

/// let mut map: HashMap<&str, usize> = HashMap::new();
/// map.entry("poneyland").or_insert(12);
///
/// assert_eq!(map["poneyland"], 12);
Copy link
Member

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.

Copy link
Member Author

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.

Copy link
Member

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.

Copy link
Member Author

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.

@GuillaumeGomez
Copy link
Member Author

@bors: r-

@GuillaumeGomez
Copy link
Member Author

Updated.

@GuillaumeGomez
Copy link
Member Author

Updated.

@steveklabnik
Copy link
Member

@bors: r+ rollup

@bors
Copy link
Contributor

bors commented Jul 25, 2016

📌 Commit ec33dab has been approved by steveklabnik

steveklabnik added a commit to steveklabnik/rust that referenced this pull request Jul 25, 2016
bors added a commit that referenced this pull request Jul 25, 2016
Rollup of 13 pull requests

- Successful merges: #34461, #34609, #34732, #34850, #34894, #34935, #34974, #34990, #34995, #35001, #35009, #35010, #35028
- Failed merges:
@bors
Copy link
Contributor

bors commented Jul 26, 2016

⌛ Testing commit ec33dab with merge 1974e04...

@bors
Copy link
Contributor

bors commented Jul 26, 2016

💔 Test failed - auto-win-msvc-64-opt

@alexcrichton
Copy link
Member

@bors: retry

On Tue, Jul 26, 2016 at 4:18 AM, bors notifications@github.com wrote:

💔 Test failed - auto-win-msvc-64-opt
https://buildbot.rust-lang.org/builders/auto-win-msvc-64-opt/builds/5089


You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
#34935 (comment), or mute
the thread
https://github.com/notifications/unsubscribe-auth/AAD95IpVck0YKiPAZuuie-p01EnnmHMIks5qZe0bgaJpZM4JQvSw
.

steveklabnik added a commit to steveklabnik/rust that referenced this pull request Jul 26, 2016
bors added a commit that referenced this pull request Jul 27, 2016
@bors bors merged commit ec33dab into rust-lang:master Jul 27, 2016
@GuillaumeGomez GuillaumeGomez deleted the hash_map_doc branch July 27, 2016 09:46
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.

6 participants