Skip to content

Commit da3e31f

Browse files
committed
---
yaml --- r: 153015 b: refs/heads/try2 c: d90b71c h: refs/heads/master i: 153013: b3db1e4 153011: 87e5dd9 153007: fab8dac v: v3
1 parent ad447f5 commit da3e31f

File tree

2 files changed

+53
-2
lines changed

2 files changed

+53
-2
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ refs/heads/snap-stage3: 78a7676898d9f80ab540c6df5d4c9ce35bb50463
55
refs/heads/try: 519addf6277dbafccbb4159db4b710c37eaa2ec5
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
8-
refs/heads/try2: c1ff089c275592044057841673256ec78d6c400c
8+
refs/heads/try2: d90b71cff68ec3748b9f42063513773da57e01e2
99
refs/heads/dist-snap: ba4081a5a8573875fed17545846f6f6902c8ba8d
1010
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1111
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

branches/try2/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)