aboutsummaryrefslogtreecommitdiff
path: root/libcore/hash/mod.rs
diff options
context:
space:
mode:
authorpravic <[email protected]>2016-06-06 23:07:53 +0300
committerpravic <[email protected]>2016-06-06 23:07:53 +0300
commitf2db0929feeb53567655dbdebba7e6b1c3f2f69e (patch)
treec2cf041f838782f9ddd8994146f52e8f498bfe07 /libcore/hash/mod.rs
parentadd 'netio' native import library (diff)
parentMerge branch 'nofp_patch' into libcore_nofp (diff)
downloadkmd-env-rs-master.tar.xz
kmd-env-rs-master.zip
Merge branch 'libcore_nofp'HEADmaster
Diffstat (limited to 'libcore/hash/mod.rs')
-rw-r--r--libcore/hash/mod.rs30
1 files changed, 28 insertions, 2 deletions
diff --git a/libcore/hash/mod.rs b/libcore/hash/mod.rs
index 4d0fed9..051eb97 100644
--- a/libcore/hash/mod.rs
+++ b/libcore/hash/mod.rs
@@ -38,7 +38,7 @@
//! ```
//!
//! If you need more control over how a value is hashed, you need to implement
-//! the trait `Hash`:
+//! the `Hash` trait:
//!
//! ```rust
//! use std::hash::{Hash, Hasher, SipHasher};
@@ -97,7 +97,33 @@ mod sip;
/// In other words, if two keys are equal, their hashes should also be equal.
/// `HashMap` and `HashSet` both rely on this behavior.
///
-/// This trait can be used with `#[derive]`.
+/// ## Derivable
+///
+/// This trait can be used with `#[derive]` if all fields implement `Hash`.
+/// When `derive`d, the resulting hash will be the combination of the values
+/// from calling `.hash()` on each field.
+///
+/// ## How can I implement `Hash`?
+///
+/// If you need more control over how a value is hashed, you need to implement
+/// the `Hash` trait:
+///
+/// ```
+/// use std::hash::{Hash, Hasher};
+///
+/// struct Person {
+/// id: u32,
+/// name: String,
+/// phone: u64,
+/// }
+///
+/// impl Hash for Person {
+/// fn hash<H: Hasher>(&self, state: &mut H) {
+/// self.id.hash(state);
+/// self.phone.hash(state);
+/// }
+/// }
+/// ```
#[stable(feature = "rust1", since = "1.0.0")]
pub trait Hash {
/// Feeds this value into the state given, updating the hasher as necessary.