Skip to content

Commit

Permalink
Rollup merge of rust-lang#40505 - frewsxcv:hash-docs, r=alexcrichton
Browse files Browse the repository at this point in the history
A few improvements to the `core::hash` top-level docs.

Primarily opened to address the concerns brought up in
rust-lang#40498.

* run rustfmt on code blocks
* use `DefaultHasher` instead of deprecated `SipHasher`
* rename `hash` to `calculate_hash` to prevent confusion with the `hash`
  method
  • Loading branch information
frewsxcv authored Mar 15, 2017
2 parents 16aa039 + 5cc056a commit cc1e513
Showing 1 changed file with 31 additions and 13 deletions.
44 changes: 31 additions & 13 deletions src/libcore/hash/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
//! # Examples
//!
//! ```rust
//! use std::hash::{Hash, SipHasher, Hasher};
//! use std::collections::hash_map::DefaultHasher;
//! use std::hash::{Hash, Hasher};
//!
//! #[derive(Hash)]
//! struct Person {
Expand All @@ -25,13 +26,21 @@
//! phone: u64,
//! }
//!
//! let person1 = Person { id: 5, name: "Janet".to_string(), phone: 555_666_7777 };
//! let person2 = Person { id: 5, name: "Bob".to_string(), phone: 555_666_7777 };
//! let person1 = Person {
//! id: 5,
//! name: "Janet".to_string(),
//! phone: 555_666_7777,
//! };
//! let person2 = Person {
//! id: 5,
//! name: "Bob".to_string(),
//! phone: 555_666_7777,
//! };
//!
//! assert!(hash(&person1) != hash(&person2));
//! assert!(calculate_hash(&person1) != calculate_hash(&person2));
//!
//! fn hash<T: Hash>(t: &T) -> u64 {
//! let mut s = SipHasher::new();
//! fn calculate_hash<T: Hash>(t: &T) -> u64 {
//! let mut s = DefaultHasher::new();
//! t.hash(&mut s);
//! s.finish()
//! }
Expand All @@ -43,11 +52,12 @@
//! [`Hash`]: trait.Hash.html
//!
//! ```rust
//! use std::hash::{Hash, Hasher, SipHasher};
//! use std::collections::hash_map::DefaultHasher;
//! use std::hash::{Hash, Hasher};
//!
//! struct Person {
//! id: u32,
//! # #[allow(dead_code)]
//! # #[allow(dead_code)]
//! name: String,
//! phone: u64,
//! }
Expand All @@ -59,13 +69,21 @@
//! }
//! }
//!
//! let person1 = Person { id: 5, name: "Janet".to_string(), phone: 555_666_7777 };
//! let person2 = Person { id: 5, name: "Bob".to_string(), phone: 555_666_7777 };
//! let person1 = Person {
//! id: 5,
//! name: "Janet".to_string(),
//! phone: 555_666_7777,
//! };
//! let person2 = Person {
//! id: 5,
//! name: "Bob".to_string(),
//! phone: 555_666_7777,
//! };
//!
//! assert_eq!(hash(&person1), hash(&person2));
//! assert_eq!(calculate_hash(&person1), calculate_hash(&person2));
//!
//! fn hash<T: Hash>(t: &T) -> u64 {
//! let mut s = SipHasher::new();
//! fn calculate_hash<T: Hash>(t: &T) -> u64 {
//! let mut s = DefaultHasher::new();
//! t.hash(&mut s);
//! s.finish()
//! }
Expand Down

0 comments on commit cc1e513

Please sign in to comment.