Skip to content

BuildHasherDefault: remove #30

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 31, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
69 changes: 0 additions & 69 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
//!
Expand All @@ -37,10 +34,6 @@
//!
//! The trait bound `H: hash32::Hasher` is *more* restrictive as it only accepts 32-bit hashers.
//!
//! The `BuildHasherDefault<H>` 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
Expand All @@ -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<H> {
_marker: PhantomData<H>,
}

impl<H> Default for BuildHasherDefault<H> {
fn default() -> Self {
Self {
_marker: PhantomData,
}
}
}

impl<H> Clone for BuildHasherDefault<H> {
fn clone(&self) -> Self {
Self::default()
}
}

impl<H> PartialEq for BuildHasherDefault<H> {
fn eq(&self, _other: &Self) -> bool {
true
}
}

impl<H> Eq for BuildHasherDefault<H> {}

impl<H> fmt::Debug for BuildHasherDefault<H> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.pad("BuildHasherDefault")
}
}

impl<H> BuildHasherDefault<H> {
/// `const` constructor
pub const fn new() -> Self {
Self {
_marker: PhantomData,
}
}
}

impl<H> BuildHasher for BuildHasherDefault<H>
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
Expand Down