#hashing #hash #generic #endian #no-alloc #depend #endian-independent

no-std anyhash

Traits and utilities for making hashes of any type

3 releases

0.1.3 Nov 12, 2024
0.1.2 Apr 1, 2024
0.1.1 Apr 1, 2024
0.1.0 Jan 14, 2024

#789 in Algorithms

Download history 8/week @ 2024-09-18 43/week @ 2024-09-25 74/week @ 2024-10-02 81/week @ 2024-10-09 270/week @ 2024-10-16 368/week @ 2024-10-23 341/week @ 2024-10-30 348/week @ 2024-11-06 319/week @ 2024-11-13 450/week @ 2024-11-20 455/week @ 2024-11-27 313/week @ 2024-12-04

1,669 downloads per month

Zlib OR MIT OR Apache-2.0

100KB
2.5K SLoC

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.

Dependencies

~210–790KB
~18K SLoC