Skip to content

Commit d90b71c

Browse files
committed
std: move the hash docstring over to std::hash.
1 parent c1ff089 commit d90b71c

File tree

1 file changed

+52
-1
lines changed

1 file changed

+52
-1
lines changed

src/libstd/hash.rs

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,58 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
//! Generic hashing support.
11+
/*!
12+
* Generic hashing support.
13+
*
14+
* This module provides a generic way to compute the hash of a value. The
15+
* simplest way to make a type hashable is to use `#[deriving(Hash)]`:
16+
*
17+
* # Example
18+
*
19+
* ```rust
20+
* use std::hash;
21+
* use std::hash::Hash;
22+
*
23+
* #[deriving(Hash)]
24+
* struct Person {
25+
* id: uint,
26+
* name: String,
27+
* phone: u64,
28+
* }
29+
*
30+
* let person1 = Person { id: 5, name: "Janet".to_string(), phone: 555_666_7777 };
31+
* let person2 = Person { id: 5, name: "Bob".to_string(), phone: 555_666_7777 };
32+
*
33+
* assert!(hash::hash(&person1) != hash::hash(&person2));
34+
* ```
35+
*
36+
* If you need more control over how a value is hashed, you need to implement
37+
* the trait `Hash`:
38+
*
39+
* ```rust
40+
* use std::hash;
41+
* use std::hash::Hash;
42+
* use std::hash::sip::SipState;
43+
*
44+
* struct Person {
45+
* id: uint,
46+
* name: String,
47+
* phone: u64,
48+
* }
49+
*
50+
* impl Hash for Person {
51+
* fn hash(&self, state: &mut SipState) {
52+
* self.id.hash(state);
53+
* self.phone.hash(state);
54+
* }
55+
* }
56+
*
57+
* let person1 = Person { id: 5, name: "Janet".to_string(), phone: 555_666_7777 };
58+
* let person2 = Person { id: 5, name: "Bob".to_string(), phone: 555_666_7777 };
59+
*
60+
* assert!(hash::hash(&person1) == hash::hash(&person2));
61+
* ```
62+
*/
1263

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

0 commit comments

Comments
 (0)