about summary refs log tree commit diff
path: root/src/libstd
diff options
context:
space:
mode:
authorErick Tryzelaar <erick.tryzelaar@gmail.com>2014-07-01 07:29:16 -0700
committerErick Tryzelaar <erick.tryzelaar@gmail.com>2014-07-01 07:29:16 -0700
commitd90b71cff68ec3748b9f42063513773da57e01e2 (patch)
tree399201b3bd70291ad0b38a2865e1a5e6070c3cb0 /src/libstd
parentc1ff089c275592044057841673256ec78d6c400c (diff)
downloadrust-d90b71cff68ec3748b9f42063513773da57e01e2.tar.gz
rust-d90b71cff68ec3748b9f42063513773da57e01e2.zip
std: move the hash docstring over to std::hash.
Diffstat (limited to 'src/libstd')
-rw-r--r--src/libstd/hash.rs53
1 files changed, 52 insertions, 1 deletions
diff --git a/src/libstd/hash.rs b/src/libstd/hash.rs
index fd1bab2dd71..2cc7e70747a 100644
--- a/src/libstd/hash.rs
+++ b/src/libstd/hash.rs
@@ -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};