From 619a16d7ca30b25ce1f9b1cf5f56b19709ed3618 Mon Sep 17 00:00:00 2001 From: Alex Martens Date: Fri, 28 Mar 2025 16:26:11 -0700 Subject: [PATCH] BuildHasherDefault: remove This type existed because core::hash::BuildHasherDefault did not have a const constructor. As of 1.85 core::hash::BuildHasherDefault has a const constructor. --- CHANGELOG.md | 3 +++ src/lib.rs | 69 ---------------------------------------------------- 2 files changed, 3 insertions(+), 69 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9f3daaa..a17ebdc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/). ### Removed - Removed the `byteorder` dependency. +- Removed the `BuildHasherDefault` type. + - This type existed because `core::hash::BuildHasherDefault` did not have a const constructor. + - As of 1.85 core::hash::BuildHasherDefault has a const constructor. ## [v0.3.1] - 2022-08-09 diff --git a/src/lib.rs b/src/lib.rs index 0a8845d..4afb0ac 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -16,9 +16,6 @@ //! Since it extends `core::hash::Hasher`, `Hasher` can be used with any type which implements the //! standard `Hash` trait. //! -//! This crate also adds a version of `BuildHasherDefault` with a const constructor, to work around -//! the `core` version's lack of one. -//! //! [`core::hash`]: https://doc.rust-lang.org/std/hash/index.html //! [`finish32`]: crate::Hasher::finish32 //! @@ -37,10 +34,6 @@ //! //! The trait bound `H: hash32::Hasher` is *more* restrictive as it only accepts 32-bit hashers. //! -//! The `BuildHasherDefault` type implements the `core::hash::BuildHasher` trait so it can -//! construct both 32-bit and 64-bit hashers. To constrain the type to only produce 32-bit hasher -//! you can add the trait bound `H::Hasher: hash32::Hasher` -//! //! # MSRV //! //! This crate is guaranteed to compile on latest stable Rust. It *might* compile on older @@ -55,74 +48,12 @@ )] #![no_std] -use core::fmt; -use core::hash::BuildHasher; -use core::marker::PhantomData; - pub use crate::fnv::Hasher as FnvHasher; pub use crate::murmur3::Hasher as Murmur3Hasher; mod fnv; mod murmur3; -/// A copy of [`core::hash::BuildHasherDefault`][0], but with a const constructor. -/// -/// This will eventually be deprecated once the version in `core` becomes const-constructible -/// (presumably using `const Default`). -/// -/// [0]: https://doc.rust-lang.org/core/hash/struct.BuildHasherDefault.html -pub struct BuildHasherDefault { - _marker: PhantomData, -} - -impl Default for BuildHasherDefault { - fn default() -> Self { - Self { - _marker: PhantomData, - } - } -} - -impl Clone for BuildHasherDefault { - fn clone(&self) -> Self { - Self::default() - } -} - -impl PartialEq for BuildHasherDefault { - fn eq(&self, _other: &Self) -> bool { - true - } -} - -impl Eq for BuildHasherDefault {} - -impl fmt::Debug for BuildHasherDefault { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - f.pad("BuildHasherDefault") - } -} - -impl BuildHasherDefault { - /// `const` constructor - pub const fn new() -> Self { - Self { - _marker: PhantomData, - } - } -} - -impl BuildHasher for BuildHasherDefault -where - H: Default + core::hash::Hasher, -{ - type Hasher = H; - - fn build_hasher(&self) -> Self::Hasher { - H::default() - } -} - /// An extension of [core::hash::Hasher][0] for hashers which use 32 bits. /// /// For hashers which implement this trait, the standard `finish` method should just return a