Crate anyhash

Source
Expand description

§Traits and utilities for making hashes of any type

This crate provides the Hash, Hasher and BuildHasher traits, which are almost exactly like their counterparts in core/std, except that Hasher and BuildHasher are generic over the type of the hash, and Hash can be used with any type of hash. A derive macro for Hash is available.

The Hash trait uses the HasherWrite trait for hashing, which has all the write methods you’re familiar with from Hasher in core except for the finish method, because Hash doesn’t know the type of the hash.

Hashing algorithms implement the Hasher and HasherWrite traits. Hasher is generic over the type of the hash and only contains the finish method. It depends on HasherWrite, so you can use it just like Hasher from core.

This crate also provides tools for working with endian independent hashes, and a few hasher implementations.

§Features

The crate is no_std and doesn’t enable any features by default. The following features are available:

  • alloc: Enable trait implementations for the standard alloc crate.
  • std: Enable trait implementations for the standard std crate. Implies alloc.

Optional integrations:

  • bnum: Implement Hash for the bnum crate’s types, and add support for using them as the hash type for the built-in hashers that can use them.

Built-in hashers:

  • fnv: Hashers using the Fnv1 and Fnv1a algorithms.
  • spooky: Hashers using the SpookyHash algorithm. V1 and V2 are available.
  • xxh64: Hasher using the Xxh64 algorithm.

Modules§

fnvfnv
Hasher and collections using the Fnv hashing algorithm.
spookyspooky
Hasher and collections using the SpookyHash algorithm.
xxh64xxh64
Hasher and collections using the Xxh64 hashing algorithm.

Macros§

impl_core_build_hasher
Implement core::Hash::BuildHasher for types that already implement BuildHasher<u64>.
impl_core_hash
Implement core::Hash::Hash for types that already implement Hash.
impl_core_hasher
Implement core::Hash::Hasher for types that already implement Hasher<u64>.
impl_hash
Implement Hash for types that already implement core::hash::Hash. Only use this if you can’t use the derive macro or implement Hash yourself. This will panic if core::hash::Hasher::finish is called during hashing.

Structs§

BuildHasherDefault
Used to create a default BuildHasher instance for types that implement Hasher and Default.
HasherBe
Wrapper for types implementing Hasher<T> to change native endian writes to big endian.
HasherBeBuildHasher
BuildHasher for making HasherBe hashers.
HasherLe
Wrapper for types implementing Hasher<T> to change native endian writes to little endian.
HasherLeBuildHasher
BuildHasher for making HasherLe hashers.

Traits§

BuildHasher
A trait for creating instances of Hasher that make hashes of type T.
EndianIndependentAlgorithm
Marker trait for hashers that, given the same byte stream, calculates the same hash on hosts of different endiannesses.
EndianIndependentHasher
Automatically implemented for Hashers that implement both EndianIndependentAlgorithm and EndianIndependentWrites.
EndianIndependentWrites
Marker trait for hashers whose write methods write data in the same order regardless of the endianness of the host. Be aware that a type may write endian dependent data to the hasher in other ways, so this isn’t a guarantee.
Hash
A hashable type.
Hasher
A trait for hashing an arbitrary stream of bytes. The write methods are defined in the HasherWrite trait.
HasherWrite
A trait for writing data to a hasher.

Derive Macros§

Hash
Derive macro for Hash.