Skip to content

Commit 9e8274d

Browse files
Urgaumichaelwoerister
authored andcommitted
Improve README with usage section and more descriptive section
1 parent 2490f48 commit 9e8274d

File tree

1 file changed

+31
-1
lines changed

1 file changed

+31
-1
lines changed

README.md

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,32 @@
11
# rustc-stable-hash
2-
A stable hashing algorithm used by rustc: cross-platform, deterministic, not secure
2+
3+
[![crates.io](https://img.shields.io/crates/v/rustc-stable-hash.svg)](https://crates.io/crates/rustc-stable-hash)
4+
[![Documentation](https://docs.rs/rustc-stable-hash/badge.svg)](https://docs.rs/rustc-stable-hash)
5+
6+
A stable hashing algorithm used by `rustc`: cross-platform, deterministic, not secure.
7+
8+
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.
9+
10+
Currently, this crate provides it's own implementation of 128-bit `SipHasher`: `SipHasher128`; with `StableSipHasher128` for the stable variant.
11+
12+
## Usage
13+
14+
```rust
15+
use rustc_stable_hash::hashers::{StableSipHasher128, SipHasher128Hash};
16+
use rustc_stable_hash::FromStableHash;
17+
use std::hash::Hasher;
18+
19+
struct Hash128([u64; 2]);
20+
impl FromStableHash for Hash128 {
21+
type Hash = SipHasher128Hash;
22+
23+
fn from(SipHasher128Hash(hash): SipHasher128Hash) -> Hash128 {
24+
Hash128(hash)
25+
}
26+
}
27+
28+
let mut hasher = StableSipHasher128::new();
29+
hasher.write_usize(0xFA);
30+
31+
let hash: Hash128 = hasher.finish();
32+
```

0 commit comments

Comments
 (0)