Skip to content

Commit 54ab425

Browse files
committed
Add fn const BuildHasherDefault::new
Because `HashMap::with_hasher` constness is being stabilized this will in turn allow creating empty HashMap<K,V,BuildHasherDefault<H>> in const context for any H: Default + Hasher.
1 parent 45796d1 commit 54ab425

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

Diff for: library/core/src/hash/mod.rs

+13-1
Original file line numberDiff line numberDiff line change
@@ -752,6 +752,18 @@ pub trait BuildHasher {
752752
#[stable(since = "1.7.0", feature = "build_hasher")]
753753
pub struct BuildHasherDefault<H>(marker::PhantomData<fn() -> H>);
754754

755+
impl<H> BuildHasherDefault<H> {
756+
/// Creates a new BuildHasherDefault for Hasher `H`.
757+
#[unstable(
758+
feature = "build_hasher_default_const_new",
759+
issue = "123197",
760+
reason = "recently added"
761+
)]
762+
pub const fn new() -> Self {
763+
BuildHasherDefault(marker::PhantomData)
764+
}
765+
}
766+
755767
#[stable(since = "1.9.0", feature = "core_impl_debug")]
756768
impl<H> fmt::Debug for BuildHasherDefault<H> {
757769
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
@@ -778,7 +790,7 @@ impl<H> Clone for BuildHasherDefault<H> {
778790
#[stable(since = "1.7.0", feature = "build_hasher")]
779791
impl<H> Default for BuildHasherDefault<H> {
780792
fn default() -> BuildHasherDefault<H> {
781-
BuildHasherDefault(marker::PhantomData)
793+
Self::new()
782794
}
783795
}
784796

0 commit comments

Comments
 (0)