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.
This commit is contained in:
Arthur Carcano 2024-03-29 17:09:34 +01:00
parent 45796d1c24
commit 54ab425839

View file

@ -752,6 +752,18 @@ fn hash_one<T: Hash>(&self, x: T) -> u64
#[stable(since = "1.7.0", feature = "build_hasher")]
pub struct BuildHasherDefault<H>(marker::PhantomData<fn() -> H>);
impl<H> BuildHasherDefault<H> {
/// Creates a new BuildHasherDefault for Hasher `H`.
#[unstable(
feature = "build_hasher_default_const_new",
issue = "123197",
reason = "recently added"
)]
pub const fn new() -> Self {
BuildHasherDefault(marker::PhantomData)
}
}
#[stable(since = "1.9.0", feature = "core_impl_debug")]
impl<H> fmt::Debug for BuildHasherDefault<H> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
@ -778,7 +790,7 @@ fn clone(&self) -> BuildHasherDefault<H> {
#[stable(since = "1.7.0", feature = "build_hasher")]
impl<H> Default for BuildHasherDefault<H> {
fn default() -> BuildHasherDefault<H> {
BuildHasherDefault(marker::PhantomData)
Self::new()
}
}