Skip to content

Commit ca7f550

Browse files
committed
Add a public hasher function for HashSet and HashMap
1 parent b94cd7a commit ca7f550

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

src/libstd/collections/hash/map.rs

+7
Original file line numberDiff line numberDiff line change
@@ -642,6 +642,13 @@ impl<K, V, S> HashMap<K, V, S>
642642
HashMap::with_capacity_and_hasher(capacity, hash_state)
643643
}
644644

645+
/// Returns a reference to the map's hasher.
646+
#[unstable(feature = "hashmap_public_hasher", reason = "don't want to make insta-stable",
647+
issue = "31262")]
648+
pub fn hasher(&self) -> &S {
649+
&self.hash_builder
650+
}
651+
645652
/// Returns the number of elements the map can hold without reallocating.
646653
///
647654
/// This number is a lower bound; the `HashMap<K, V>` might be able to hold

src/libstd/collections/hash/set.rs

+7
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,13 @@ impl<T, S> HashSet<T, S>
193193
}
194194
}
195195

196+
/// Returns a reference to the set's hasher.
197+
#[unstable(feature = "hashmap_public_hasher", reason = "don't want to make insta-stable",
198+
issue = "31262")]
199+
pub fn hasher(&self) -> &S {
200+
self.map.hasher()
201+
}
202+
196203
/// Deprecated, renamed to `with_hasher`
197204
#[inline]
198205
#[unstable(feature = "hashmap_hasher", reason = "hasher stuff is unclear",

0 commit comments

Comments
 (0)