2 releases

0.1.1 Dec 10, 2024
0.1.0 Jul 11, 2024

#19 in Programming languages

Download history 9176/week @ 2024-10-21 10111/week @ 2024-10-28 9789/week @ 2024-11-04 11688/week @ 2024-11-11 12790/week @ 2024-11-18 13046/week @ 2024-11-25 13391/week @ 2024-12-02 15235/week @ 2024-12-09 17265/week @ 2024-12-16 12451/week @ 2024-12-23 13485/week @ 2024-12-30 15328/week @ 2025-01-06 13559/week @ 2025-01-13 11776/week @ 2025-01-20 12007/week @ 2025-01-27 10598/week @ 2025-02-03

49,925 downloads per month
Used in 15 crates (via jomy-ap-rustc_data_struct…)

Apache-2.0 OR MIT

53KB
887 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