Skip to content

Improve std::hash docs - #41125

Merged
bors merged 5 commits into
rust-lang:masterfrom
chordowl:std-hash-docs
Apr 15, 2017
Merged

Improve std::hash docs#41125
bors merged 5 commits into
rust-lang:masterfrom
chordowl:std-hash-docs

Conversation

@chordowl

@chordowlchordowl commented Apr 6, 2017

Copy link
Copy Markdown
Contributor

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
@chordowlchordowl changed the title Improve std::hash: docsImprove std::hash docsApr 6, 2017
Comment threadsrc/libcore/hash/mod.rs Outdated
/// assert_eq!(hasher_1.finish(), hasher_2.finish());
/// ```
///
/// [`build_hasher`]: #method.build_hasher

Copy link
Copy Markdown
ContributorAuthor

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
Copy Markdown
Contributor

/cc @rust-lang/docs

Comment threadsrc/libcore/hash/mod.rs Outdated
/// #[derive(Hash)]
/// struct Rustacean {
/// name: String,
/// country: String,

Copy link
Copy Markdown
Contributor

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.

Comment threadsrc/libcore/hash/mod.rs Outdated
///
/// 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
Copy Markdown
Contributor

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
Copy Markdown
ContributorAuthor

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 😅).

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

Copy link
Copy Markdown
Contributor

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

@bors r+ rollup

@bors

bors commented Apr 15, 2017

Copy link
Copy Markdown
Collaborator

📌 Commit 12d7c3d has been approved by frewsxcv

@frewsxcvfrewsxcv 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

bors commented Apr 15, 2017

Copy link
Copy Markdown
Collaborator

⌛ 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
Fixesrust-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
@frewsxcvfrewsxcv mentioned this pull request Apr 15, 2017
@frewsxcv

Copy link
Copy Markdown
Contributor

@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:masterApr 15, 2017
@chordowl
chordowl deleted the std-hash-docs branch April 15, 2017 08:48
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-docsArea: Documentation for any part of the project, including the compiler, standard library, and toolsS-waiting-on-borsStatus: 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

@chordowl@steveklabnik@frewsxcv@bors@alexcrichton@Mark-Simulacrum