Skip to content

Commit

Permalink
rename to anyhash
Browse files Browse the repository at this point in the history
  • Loading branch information
maia-s committed Jan 14, 2024
1 parent aec21f7 commit 28d8f2b
Show file tree
Hide file tree
Showing 21 changed files with 63 additions and 97 deletions.
30 changes: 15 additions & 15 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[workspace]
members = ["hash-t", "hash-t-macros"]
members = ["anyhash", "anyhash-macros"]
resolver = "2"
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
This repository contains the [hash-t](hash-t) and [hash-t-macros](hash-t-macros) crates.
This repository contains the [anyhash](anyhash) and [anyhash-macros](anyhash-macros) crates.

See [hash-t/README.md](hash-t/README.md).
See [anyhash/README.md](anyhash/README.md).
2 changes: 1 addition & 1 deletion hash-t-macros/Cargo.toml → anyhash-macros/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[package]
name = "hash-t-macros"
name = "anyhash-macros"
version = "0.1.0"
edition = "2021"
authors = ["Maia <[email protected]>"]
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
1 change: 1 addition & 0 deletions anyhash-macros/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This crate provides proc macros for the `anyhash` crate. Don't use this directly.
42 changes: 4 additions & 38 deletions hash-t-macros/src/lib.rs → anyhash-macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ use syn::{
};

fn crate_root() -> TokenStream {
quote!(::hash_t)
quote!(::anyhash)
}

#[proc_macro_derive(HashT)]
#[proc_macro_derive(Hash)]
#[allow(non_snake_case)]
pub fn derive_hash_t(input: TokenStream1) -> TokenStream1 {
pub fn derive_anyhash(input: TokenStream1) -> TokenStream1 {
let root = crate_root();
let hash = quote!(#root::Hash);
let hasher_write = quote!(#root::HasherWrite);
Expand Down Expand Up @@ -274,7 +274,7 @@ pub fn impl_core_build_hasher(input: TokenStream1) -> TokenStream1 {

#[proc_macro]
#[allow(non_snake_case)]
pub fn impl_hash_t(input: TokenStream1) -> TokenStream1 {
pub fn impl_hash(input: TokenStream1) -> TokenStream1 {
let root = crate_root();
let hash = quote!(#root::Hash);
let hasher_write = quote!(#root::HasherWrite);
Expand Down Expand Up @@ -317,40 +317,6 @@ pub fn impl_hash_t(input: TokenStream1) -> TokenStream1 {
output.into()
}

#[proc_macro]
pub fn impl_hash_u64(input: TokenStream1) -> TokenStream1 {
let root = crate_root();
let hash_t = quote!(#root::Hash);
let hasher_t = quote!(#root::Hasher);

let input = parse_macro_input!(input as IdentsWithGenerics);
let mut output = TokenStream::new();

for IdentWithGenerics {
impl_generics,
ident,
use_generics,
mut where_clause,
} in input.punctuated
{
let where_ = fix_where(where_clause.as_mut());
quote! {
impl #impl_generics #hash_t<u64> for #ident #use_generics #where_ #where_clause
Self: ::core::hash::Hash,
{
#[inline]
fn hash<H: #hasher_t<u64>>(&self, state: &mut H) {
<Self as ::core::hash::Hash>::hash(
self, &mut #root::internal::WrapU64ForCore::new(state)
)
}
}
}
.to_tokens(&mut output);
}
output.into()
}

fn fix_where(wc: Option<&mut WhereClause>) -> Option<Token![where]> {
if let Some(wc) = wc {
if wc.predicates.is_empty() {
Expand Down
4 changes: 2 additions & 2 deletions hash-t/Cargo.toml → anyhash/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[package]
name = "hash-t"
name = "anyhash"
version = "0.1.0"
edition = "2021"
authors = ["Maia <[email protected]>"]
Expand All @@ -22,7 +22,7 @@ spooky = ["bytemuck"]
xxh64 = ["bytemuck"]

[dependencies]
hash-t-macros = { path = "../hash-t-macros" }
anyhash-macros = { path = "../anyhash-macros" }
bnum = { version = "0.10", optional = true }
bytemuck = { version = "1.14", features = ["min_const_generics"], optional = true }

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
16 changes: 8 additions & 8 deletions hash-t/src/impls.rs → anyhash/src/impls.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::{impl_hash_t, Hash, Hasher, HasherWrite};
use crate::{impl_hash, Hash, Hasher, HasherWrite};

macro_rules! impl_hasher_t_deref {
() => {
Expand Down Expand Up @@ -265,7 +265,7 @@ mod core_impls {
time::Duration,
};

impl_hash_t!(Layout; TypeId);
impl_hash!(Layout; TypeId);

impl Hash for Ordering {
#[inline]
Expand All @@ -279,7 +279,7 @@ mod core_impls {
fn hash<H: HasherWrite>(&self, _: &mut H) {}
}

impl_hash_t!(impl<T> Discriminant<T>);
impl_hash!(impl<T> Discriminant<T>);

impl<T: ?Sized + Hash> Hash for ManuallyDrop<T> {
#[inline]
Expand All @@ -304,7 +304,7 @@ mod core_impls {
}

// RangeInclusive has private internal state
impl_hash_t!(impl<I: core::hash::Hash> RangeInclusive<I>);
impl_hash!(impl<I: core::hash::Hash> RangeInclusive<I>);

impl<T: Hash> Hash for Bound<T> {
#[inline]
Expand Down Expand Up @@ -339,7 +339,7 @@ mod core_impls {
}
}

impl_hash_t!(Location<'_>);
impl_hash!(Location<'_>);

impl<P: Deref<Target = impl Hash>> Hash for Pin<P> {
#[inline]
Expand Down Expand Up @@ -384,7 +384,7 @@ mod core_impls {
}
}

impl_hash_t!(Duration);
impl_hash!(Duration);

impl_empty_hash! {
Infallible, Error, PhantomPinned, RangeFull
Expand Down Expand Up @@ -489,7 +489,7 @@ mod alloc_impls {
}
}

impl_hash_t!(impl<T: core::hash::Hash> BTreeSet<T>);
impl_hash!(impl<T: core::hash::Hash> BTreeSet<T>);

impl<T: Hash> Hash for LinkedList<T> {
#[inline]
Expand Down Expand Up @@ -531,7 +531,7 @@ mod std_impls {
time::{Instant, SystemTime},
};

impl_hash_t!(
impl_hash!(
OsStr;
OsString;
FileType;
Expand Down
File renamed without changes.
58 changes: 29 additions & 29 deletions hash-t/src/lib.rs → anyhash/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#![deny(missing_docs)]
#![doc = include_str!("../README.md")]

extern crate self as hash_t;
extern crate self as anyhash;

#[cfg(feature = "alloc")]
extern crate alloc;
Expand All @@ -15,13 +15,13 @@ extern crate std;
use core::{fmt::Debug, marker::PhantomData};

/// Derive macro for [`Hash`].
pub use hash_t_macros::HashT;
pub use anyhash_macros::Hash;

/// Implement `::core::Hash::Hash` for types that already implement [`Hash<u64>`].
///
/// ```
/// # use hash_t::*;
/// # #[derive(HashT)]
/// # use anyhash::*;
/// # #[derive(anyhash::Hash)]
/// # struct MyType;
/// // Implements `::core::Hash:Hash` for `MyType`.
/// impl_core_hash!(MyType);
Expand All @@ -30,8 +30,8 @@ pub use hash_t_macros::HashT;
/// You can pass multiple types as arguments. Types are separated by `;`.
///
/// ```
/// # use hash_t::*;
/// # #[derive(HashT)]
/// # use anyhash::*;
/// # #[derive(anyhash::Hash)]
/// # struct MyOtherType<T>(T);
/// // Implements `::core::Hash:Hash` for `MyOtherType<u32>` and `MyOtherType<u64>`.
/// impl_core_hash!(MyOtherType<u32>; MyOtherType<u64>);
Expand All @@ -40,24 +40,24 @@ pub use hash_t_macros::HashT;
/// You can also pass generic types using the `impl` keyword.
///
/// ```
/// # use hash_t::*;
/// # use anyhash::*;
/// # use core::fmt::Display;
/// # #[derive(HashT)]
/// # #[derive(anyhash::Hash)]
/// # struct MyType<T>(T);
/// # #[derive(HashT)]
/// # #[derive(anyhash::Hash)]
/// # struct MyOtherType<'a, T, U, V>(core::marker::PhantomData<&'a (T, U, V)>);
/// // Implements `::core::Hash:Hash` for `MyType` and `MyOtherType`.
/// impl_core_hash! {
/// impl<T> MyType<T>;
/// impl<'a, T, U: 'a> MyOtherType<'a, T, u32, U> where Self: Display;
/// }
/// ```
pub use hash_t_macros::impl_core_hash;
pub use anyhash_macros::impl_core_hash;

/// Implement `::core::Hash::Hasher` for types that already implement [`Hasher<u64>`].
///
/// ```
/// # use hash_t::*;
/// # use anyhash::*;
/// # struct MyType;
/// # impl Hasher<u64> for MyType {
/// # fn finish(&self) -> u64 { 0 }
Expand All @@ -72,7 +72,7 @@ pub use hash_t_macros::impl_core_hash;
/// You can pass multiple types as arguments. Types are separated by `;`.
///
/// ```
/// # use hash_t::*;
/// # use anyhash::*;
/// # struct MyOtherType<T>(T);
/// # impl<T> Hasher<u64> for MyOtherType<T> {
/// # fn finish(&self) -> u64 { 0 }
Expand All @@ -87,7 +87,7 @@ pub use hash_t_macros::impl_core_hash;
/// You can also pass generic types using the `impl` keyword.
///
/// ```
/// # use hash_t::*;
/// # use anyhash::*;
/// # use core::fmt::Display;
/// # struct MyType<T>(T);
/// # impl<T> Hasher<u64> for MyType<T> {
Expand All @@ -109,12 +109,12 @@ pub use hash_t_macros::impl_core_hash;
/// impl<'a, T, U: 'a> MyOtherType<'a, T, u32, U> where Self: Display;
/// }
/// ```
pub use hash_t_macros::impl_core_hasher;
pub use anyhash_macros::impl_core_hasher;

/// Implement `::core::Hash::BuildHasher` for types that already implement [`BuildHasher<u64>`].
///
/// ```
/// # use hash_t::*;
/// # use anyhash::*;
/// # struct H;
/// # impl Hasher<u64> for H {
/// # fn finish(&self) -> u64 { 0 }
Expand All @@ -134,7 +134,7 @@ pub use hash_t_macros::impl_core_hasher;
/// You can pass multiple types as arguments. Types are separated by `;`.
///
/// ```
/// # use hash_t::*;
/// # use anyhash::*;
/// # struct H;
/// # impl Hasher<u64> for H {
/// # fn finish(&self) -> u64 { 0 }
Expand All @@ -154,7 +154,7 @@ pub use hash_t_macros::impl_core_hasher;
/// You can also pass generic types using the `impl` keyword.
///
/// ```
/// # use hash_t::*;
/// # use anyhash::*;
/// # use core::fmt::Display;
/// # struct H;
/// # impl Hasher<u64> for H {
Expand All @@ -179,45 +179,45 @@ pub use hash_t_macros::impl_core_hasher;
/// impl<'a, T, U: 'a> MyOtherType<'a, T, u32, U> where Self: Display;
/// }
/// ```
pub use hash_t_macros::impl_core_build_hasher;
pub use anyhash_macros::impl_core_build_hasher;

/// Implement [`Hash`] for types that already implement `::core::hash::Hash`.
/// This will panic if `::core::hash::Hasher::finish` is called during hashing.
///
/// ```
/// # use hash_t::*;
/// # #[derive(Hash)]
/// # use anyhash::*;
/// # #[derive(core::hash::Hash)]
/// # struct MyType;
/// // Implements `Hash` for `MyType`.
/// impl_hash_t!(MyType);
/// impl_hash!(MyType);
/// ```
///
/// You can pass multiple types as arguments. Types are separated by `;`.
///
/// ```
/// # use hash_t::*;
/// # #[derive(Hash)]
/// # use anyhash::*;
/// # #[derive(core::hash::Hash)]
/// # struct MyOtherType<T>(T);
/// // Implements `Hash` for `MyOtherType<u32>` and `MyOtherType<u64>`.
/// impl_hash_t!(MyOtherType<u32>; MyOtherType<u64>);
/// impl_hash!(MyOtherType<u32>; MyOtherType<u64>);
/// ```
///
/// You can also pass generic types using the `impl` keyword.
///
/// ```
/// # use hash_t::*;
/// # use anyhash::*;
/// # use core::fmt::Display;
/// # #[derive(Hash)]
/// # #[derive(core::hash::Hash)]
/// # struct MyType<T>(T);
/// # #[derive(Hash)]
/// # #[derive(core::hash::Hash)]
/// # struct MyOtherType<'a, T, U, V>(core::marker::PhantomData<&'a (T, U, V)>);
/// // Implements `Hash` for `MyType` and `MyOtherType`.
/// impl_hash_t! {
/// impl_hash! {
/// impl<T> MyType<T>;
/// impl<'a, T, U: 'a> MyOtherType<'a, T, u32, U> where Self: Display;
/// }
/// ```
pub use hash_t_macros::impl_hash_t;
pub use anyhash_macros::impl_hash;

macro_rules! define_writes_for_hasher {
(native endian) => {
Expand Down
File renamed without changes.
File renamed without changes.
1 change: 0 additions & 1 deletion hash-t-macros/README.md

This file was deleted.

0 comments on commit 28d8f2b

Please sign in to comment.