Skip to content

Commit 6f77ece

Browse files
committed
---
yaml --- r: 122675 b: refs/heads/snap-stage3 c: d90b71c h: refs/heads/master i: 122673: 12bee04 122671: afbd8cc v: v3
1 parent 5d02a4a commit 6f77ece

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
@@ -1,7 +1,7 @@
11
---
22
refs/heads/master: 1bff1ff810dcfa8064c11e2b84473f053d1f69f1
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
4-
refs/heads/snap-stage3: c1ff089c275592044057841673256ec78d6c400c
4+
refs/heads/snap-stage3: d90b71cff68ec3748b9f42063513773da57e01e2
55
refs/heads/try: 2e9d9477b848cec778ca3f07ecdf0aea6ade23de
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b

branches/snap-stage3/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)