Skip to content

Commit

Permalink
std: move the hash docstring over to std::hash.
Browse files Browse the repository at this point in the history
  • Loading branch information
erickt committed Jul 1, 2014
1 parent c1ff089 commit d90b71c
Showing 1 changed file with 52 additions and 1 deletion.
53 changes: 52 additions & 1 deletion src/libstd/hash.rs
Expand Up @@ -8,7 +8,58 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

//! Generic hashing support.
/*!
* Generic hashing support.
*
* This module provides a generic way to compute the hash of a value. The
* simplest way to make a type hashable is to use `#[deriving(Hash)]`:
*
* # Example
*
* ```rust
* use std::hash;
* use std::hash::Hash;
*
* #[deriving(Hash)]
* struct Person {
* id: uint,
* 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 };
*
* assert!(hash::hash(&person1) != hash::hash(&person2));
* ```
*
* If you need more control over how a value is hashed, you need to implement
* the trait `Hash`:
*
* ```rust
* use std::hash;
* use std::hash::Hash;
* use std::hash::sip::SipState;
*
* struct Person {
* id: uint,
* name: String,
* phone: u64,
* }
*
* impl Hash for Person {
* fn hash(&self, state: &mut SipState) {
* self.id.hash(state);
* self.phone.hash(state);
* }
* }
*
* 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::hash(&person1) == hash::hash(&person2));
* ```
*/

pub use core_collections::hash::{Hash, Hasher, Writer, hash, sip};

Expand Down

5 comments on commit d90b71c

@bors
Copy link
Contributor

@bors bors commented on d90b71c Jul 2, 2014

Choose a reason for hiding this comment

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

saw approval from alexcrichton
at erickt@d90b71c

@bors
Copy link
Contributor

@bors bors commented on d90b71c Jul 2, 2014

Choose a reason for hiding this comment

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

merging erickt/rust/hashmap = d90b71c into auto

@bors
Copy link
Contributor

@bors bors commented on d90b71c Jul 2, 2014

Choose a reason for hiding this comment

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

erickt/rust/hashmap = d90b71c merged ok, testing candidate = 7c4d8e9

@bors
Copy link
Contributor

@bors bors commented on d90b71c Jul 2, 2014

Choose a reason for hiding this comment

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

fast-forwarding master to auto = 7c4d8e9

Please sign in to comment.