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

Improve std::hash docs #41125

Merged
merged 5 commits into from
Apr 15, 2017
Merged

Improve std::hash docs #41125

merged 5 commits into from
Apr 15, 2017

Conversation

chordowl
Copy link
Contributor

@chordowl chordowl commented Apr 6, 2017

Fixes #29357.

For details on what exactly I've done, see the commit descriptions.

There are some things I'm not sure about, but would like to address before merging this so the issue can be closed; any feedback on these points would really be appriciated:

  • I didn't touch the module level docs at all. On the one hand, I think they could use a short overview over the module; on the other hand, the module really isn't that big and I don't know if I could really do anything beyond just duplicating the type's summaries...
  • I feel like the module-level examples are quite long-winded and not to the point, but I couldn't really think of anything better. Any ideas?
  • Should Hasher get an example for implementing it? There is one in the module documentation, but it only "implements" it via unimplemented! and I'm not sure what the value of that is.
  • Should Hasher's write_{int} methods get examples?

If there's anything else you'd like to see in std::hash's docs, please let me know!

r? @rust-lang/docs

Part of #29357.
* split summary and explanation more clearly
* added link to nomicon for "zero-sized"
* "does not need construction" -> say how it can be created, and that it
  doesn't need to be done with `HashMap` or `HashSet`
Part of #29357.
* split summary and explanation more clearly, while expanding the
  explanation to make the reason for `BuildHasher` existing more clear
* added an example illustrating that `Hasher`s created by one `BuildHasher`
  should be identical
* added links
* repeated the fact that hashers produced should be identical in
  `build_hasher`s method docs
Part of #29357.
* merged "Derivable" and "How can I implement `Hash`?" sections into one
  "Implementing `Hash`" section to aid coherency
* added an example for `#[derive(Hash)]`
* moved part about relation between `Hash` and `Eq` into a new "`Hash` and
  `Eq`" section; changed wording to be more consistent with `HashMap` and
  `HashSet`'s
* explicitly mentioned `#[derive(PartialEq, Eq, Hash)]` in the new section
* changed method summaries for consistency, adding links and examples
Part of #29357.
* rephrased summary sentences to be less redundant
* expanded top-level docs, adding a usage example and links to relevant
  methods (`finish`, `write` etc) as well as `Hash`
* added examples to the `finish` and `write` methods
@chordowl chordowl changed the title Improve std::hash: docs Improve std::hash docs Apr 6, 2017
/// assert_eq!(hasher_1.finish(), hasher_2.finish());
/// ```
///
/// [`build_hasher`]: #method.build_hasher
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs to link to #tymethod.build_hasher (I forgot to run linkchecker locally >_>)

@steveklabnik
Copy link
Member

/cc @rust-lang/docs

/// #[derive(Hash)]
/// struct Rustacean {
/// name: String,
/// country: String,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We tend to use four spaces for indentation.

///
/// If you need more control over how a value is hashed, you need to implement
/// the `Hash` trait:
/// If you need more control over how a value is hash, you can of course
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"how a value is hashed"

@chordowl
Copy link
Contributor Author

I have addressed the broken link as well as the indent and grammar slipups that were brought up.

Since I personally have barely any idea on how to act on the issues I outline in the initial comment, and as they weren't on the list on the issue anyway, I've decided not to address them within this PR (unless that is a dealbreaker for someone 😅).

@alexcrichton alexcrichton added the A-docs Area: documentation for any part of the project, including the compiler, standard library, and tools label Apr 11, 2017
@Mark-Simulacrum Mark-Simulacrum added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Apr 14, 2017
@frewsxcv
Copy link
Member

This is great @lukaramu, thanks so much for this! 🎉

@bors r+ rollup

@bors
Copy link
Contributor

bors commented Apr 15, 2017

📌 Commit 12d7c3d has been approved by frewsxcv

@frewsxcv frewsxcv added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Apr 15, 2017
@bors
Copy link
Contributor

bors commented Apr 15, 2017

⌛ Testing commit 12d7c3d with merge 6874b74...

frewsxcv added a commit to frewsxcv/rust that referenced this pull request Apr 15, 2017
Improve std::hash docs

Fixes rust-lang#29357.

For details on what exactly I've done, see the commit descriptions.

There are some things I'm not sure about, but would like to address before merging this so the issue can be closed; any feedback on these points would really be appriciated:
* [x] ~I didn't touch the module level docs at all. On the one hand, I think they could use a short overview over the module; on the other hand, the module really isn't that big and I don't know if I could really do anything beyond just duplicating the type's summaries...~
* [x] ~I feel like the module-level examples are quite long-winded and not to the point, but I couldn't really think of anything better. Any ideas?~
* [x] ~Should `Hasher` get an example for implementing it? There is one in the module documentation, but it only "implements" it via `unimplemented!` and I'm not sure what the value of that is.~
* [x] ~Should `Hasher`'s `write_{int}` methods get examples?~

If there's anything else you'd like to see in std::hash's docs, please let me know!

r? @rust-lang/docs
@frewsxcv
Copy link
Member

@bors retry

prioritizing rollup

bors added a commit that referenced this pull request Apr 15, 2017
Rollup of 2 pull requests

- Successful merges: #41125, #41309
- Failed merges:
@bors bors merged commit 12d7c3d into rust-lang:master Apr 15, 2017
@chordowl chordowl deleted the std-hash-docs branch April 15, 2017 08:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-docs Area: documentation for any part of the project, including the compiler, standard library, and tools S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

API Docs: hash
6 participants