]> git.lizzy.rs Git - rust.git/commitdiff
Add a public hasher function for HashSet and HashMap
authorRyan Thomas <ryan@ryant.org>
Tue, 2 Feb 2016 03:29:48 +0000 (14:29 +1100)
committerRyan Thomas <ryan@ryant.org>
Thu, 11 Feb 2016 05:01:04 +0000 (05:01 +0000)
src/libstd/collections/hash/map.rs
src/libstd/collections/hash/set.rs

index 173214eda44c79ecf5e6fb6199e5025d860b0bfa..d8748d09d0464580a50f9ac0f4e255d86bbe9e41 100644 (file)
@@ -642,6 +642,13 @@ pub fn with_capacity_and_hash_state(capacity: usize, hash_state: S)
         HashMap::with_capacity_and_hasher(capacity, hash_state)
     }
 
+    /// Returns a reference to the map's hasher.
+    #[unstable(feature = "hashmap_public_hasher", reason = "don't want to make insta-stable",
+               issue = "31262")]
+    pub fn hasher(&self) -> &S {
+        &self.hash_builder
+    }
+
     /// Returns the number of elements the map can hold without reallocating.
     ///
     /// This number is a lower bound; the `HashMap<K, V>` might be able to hold
index b5f47853afd4ef0bebbcd254f2ee5949a47d8734..5c58cd9dfbf7ce8eb8e7094625575b5ba03ceaea 100644 (file)
@@ -193,6 +193,13 @@ pub fn with_capacity_and_hasher(capacity: usize, hasher: S)
         }
     }
 
+    /// Returns a reference to the set's hasher.
+    #[unstable(feature = "hashmap_public_hasher", reason = "don't want to make insta-stable",
+               issue = "31262")]
+    pub fn hasher(&self) -> &S {
+        self.map.hasher()
+    }
+
     /// Deprecated, renamed to `with_hasher`
     #[inline]
     #[unstable(feature = "hashmap_hasher", reason = "hasher stuff is unclear",