Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Unreleased

# 0.1.1

- feat: derive `Clone` for `StableHasher` [#11][pr11]

[pr11]: https://github.com/rust-lang/rustc-stable-hash/pull/11

# 0.1.0

- Rename `StableHasherResult` to `FromStableHash` [#8][pr8]
Expand Down
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "rustc-stable-hash"
version = "0.1.0"
version = "0.1.1"
description = "A stable hashing algorithm used by rustc"
license = "Apache-2.0 OR MIT"
readme = "README.md"
Expand Down
1 change: 1 addition & 0 deletions src/stable_hasher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ pub trait ExtendedHasher: Hasher {
/// let hash: Hash128 = hasher.finish();
/// ```
#[must_use]
#[derive(Clone)]
pub struct StableHasher<H: ExtendedHasher> {
state: H,
}
Expand Down
21 changes: 21 additions & 0 deletions src/stable_hasher/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,3 +112,24 @@ fn test_isize_compression() {
check_hash(0xFF, 0xFFFFFFFFFFFFFFFF);
check_hash(u64::MAX /* -1 */, 1);
}

#[test]
fn test_cloned_hasher_output() {
// Test that integers are handled consistently across platforms.
let test_u8 = 0xAB_u8;
let test_u16 = 0xFFEE_u16;
let test_u32 = 0x445577AA_u32;

let mut h1 = StableSipHasher128::new();
test_u8.hash(&mut h1);
test_u16.hash(&mut h1);

let h2 = h1.clone();
let mut h3 = h1.clone();
// Make sure the cloned hasher can be fed more values.
test_u32.hash(&mut h3);

let h1_hash: TestHash = h1.finish();
assert_eq!(h1_hash, h2.finish());
assert_ne!(h1_hash, h3.finish());
}
Loading