2 releases

0.1.1 Nov 15, 2019
0.1.0 Apr 23, 2018

#42 in No standard library

Download history 1826/week @ 2019-12-02 1478/week @ 2019-12-09 1395/week @ 2019-12-16 1161/week @ 2019-12-23 1115/week @ 2019-12-30 1238/week @ 2020-01-06 1534/week @ 2020-01-13 1666/week @ 2020-01-20 1480/week @ 2020-01-27 2016/week @ 2020-02-03 2066/week @ 2020-02-10 1600/week @ 2020-02-17 1880/week @ 2020-02-24 1886/week @ 2020-03-02 2815/week @ 2020-03-09 2029/week @ 2020-03-16

6,597 downloads per month
Used in 127 crates (7 directly)


386 lines


32-bit hashing machinery



Licensed under either of

at your option.


Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.


32-bit hashing machinery


Because 32-bit architectures are a thing (e.g. ARM Cortex-M) and you don't want your hashing function to pull in a bunch of slow 64-bit compiler intrinsics (software implementations of 64-bit operations).

Relationship to core::hash

This crate exposes the same interfaces you'll find in core::hash: Hash, Hasher, BuildHasher and BuildHasherDefault. The main difference is that hash32::Hasher::finish returns a u32 instead of u64, and the contract of hash32::Hasher forbids the implementer from performing 64-bit (or 128-bit) operations while computing the hash.


The easiest way to implement hash32::Hash for a struct is to use the #[derive(Hash32)].

extern crate hash32_derive;

struct Ipv4Addr([u8; 4]);

# fn main() {}


This crate provides implementations of the following 32-bit hashing algorithms:


In the future we'd like to deprecate this crate in favor of making core::hash::Hasher generic over the size of the computed hash. Below is shown the planned change (but it doesn't work due to limitations in the associated_type_defaults feature):


trait Hasher {
    type Hash = u64; // default type for backwards compatibility

    fn finish(&self) -> Self::Hash; // changed
    fn write(&mut self, bytes: &[u8]);

With this change a single #[derive(Hash)] would enough to make a type hashable with 32-bit and 64-bit hashers.