Skip to content

Commit b9732ed

Browse files
committed
Auto merge of #31357 - rthomas:hashers, r=alexcrichton
add a public hasher function for HashSet and HashMap
2 parents 1de70d3 + ca7f550 commit b9732ed

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
@@ -645,6 +645,13 @@ impl<K, V, S> HashMap<K, V, S>
645645
HashMap::with_capacity_and_hasher(capacity, hash_state)
646646
}
647647

648+
/// Returns a reference to the map's hasher.
649+
#[unstable(feature = "hashmap_public_hasher", reason = "don't want to make insta-stable",
650+
issue = "31262")]
651+
pub fn hasher(&self) -> &S {
652+
&self.hash_builder
653+
}
654+
648655
/// Returns the number of elements the map can hold without reallocating.
649656
///
650657
/// 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)