3 releases

0.1.2 Mar 5, 2025
0.1.1 Dec 10, 2024
0.1.0 Jul 11, 2024

#17 in Programming languages

Download history 12426/week @ 2024-12-22 13664/week @ 2024-12-29 15069/week @ 2025-01-05 14040/week @ 2025-01-12 11768/week @ 2025-01-19 12086/week @ 2025-01-26 11466/week @ 2025-02-02 12407/week @ 2025-02-09 20316/week @ 2025-02-16 44491/week @ 2025-02-23 75175/week @ 2025-03-02 89195/week @ 2025-03-09 84640/week @ 2025-03-16 77138/week @ 2025-03-23 76193/week @ 2025-03-30 79814/week @ 2025-04-06

327,174 downloads per month
Used in 64 crates (5 directly)

Apache-2.0 OR MIT

54KB
902 lines

rustc-stable-hash

crates.io Documentation

A stable hashing algorithm used by rustc: cross-platform, deterministic, not secure.

This crate provides facilities with the StableHasher structure to create stable hashers over unstable hashers by abstracting over them the handling of endian-ness and the target usize/isize bit size difference.

Currently, this crate provides it's own implementation of 128-bit SipHasher: SipHasher128; with StableSipHasher128 for the stable variant.

Usage

use rustc_stable_hash::hashers::{StableSipHasher128, SipHasher128Hash};
use rustc_stable_hash::FromStableHash;
use std::hash::Hasher;

struct Hash128([u64; 2]);
impl FromStableHash for Hash128 {
    type Hash = SipHasher128Hash;

    fn from(SipHasher128Hash(hash): SipHasher128Hash) -> Hash128 {
        Hash128(hash)
    }
}

let mut hasher = StableSipHasher128::new();
hasher.write_usize(0xFA);

let hash: Hash128 = hasher.finish();

No runtime deps

Features