]> git.lizzy.rs Git - rust.git/commitdiff
Rollup merge of #40505 - frewsxcv:hash-docs, r=alexcrichton
authorCorey Farwell <coreyf@rwell.org>
Fri, 17 Mar 2017 12:49:03 +0000 (08:49 -0400)
committerGitHub <noreply@github.com>
Fri, 17 Mar 2017 12:49:03 +0000 (08:49 -0400)
A few improvements to the `core::hash` top-level docs.

Primarily opened to address the concerns brought up in
https://github.com/rust-lang/rust/issues/40498.

* run rustfmt on code blocks
* use `DefaultHasher` instead of deprecated `SipHasher`
* rename `hash` to `calculate_hash` to prevent confusion with the `hash`
  method

1  2 
src/libcore/hash/mod.rs

diff --combined src/libcore/hash/mod.rs
index aadeaac83d5c85d7d622e8dac1e8e68ab9bdb9e2,8c7d83232de4f0a9379c8e8d2dd002104972c15d..756d472eca8d466ca4ee33190d9713183e85ac4a
@@@ -16,7 -16,8 +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 {
  //!     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()
  //! }
  //! [`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,
  //! }
  //!     }
  //! }
  //!
- //! 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()
  //! }
@@@ -106,7 -124,7 +124,7 @@@ mod sip
  ///
  /// This trait can be used with `#[derive]` if all fields implement `Hash`.
  /// When `derive`d, the resulting hash will be the combination of the values
 -/// from calling [`.hash()`] on each field.
 +/// from calling [`.hash`] on each field.
  ///
  /// ## How can I implement `Hash`?
  ///
  /// [`Eq`]: ../../std/cmp/trait.Eq.html
  /// [`HashMap`]: ../../std/collections/struct.HashMap.html
  /// [`HashSet`]: ../../std/collections/struct.HashSet.html
 -/// [`.hash()`]: #tymethod.hash
 +/// [`.hash`]: #tymethod.hash
  #[stable(feature = "rust1", since = "1.0.0")]
  pub trait Hash {
      /// Feeds this value into the state given, updating the hasher as necessary.