diff --git a/CHANGELOG.md b/CHANGELOG.md index c98e4a8..8869b0e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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] diff --git a/Cargo.lock b/Cargo.lock index d0752af..3d98d49 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4,4 +4,4 @@ version = 3 [[package]] name = "rustc-stable-hash" -version = "0.1.0" +version = "0.1.1" diff --git a/Cargo.toml b/Cargo.toml index 976ab8c..7841416 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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" diff --git a/src/stable_hasher.rs b/src/stable_hasher.rs index 62e092c..bc5f9d9 100644 --- a/src/stable_hasher.rs +++ b/src/stable_hasher.rs @@ -88,6 +88,7 @@ pub trait ExtendedHasher: Hasher { /// let hash: Hash128 = hasher.finish(); /// ``` #[must_use] +#[derive(Clone)] pub struct StableHasher { state: H, } diff --git a/src/stable_hasher/tests.rs b/src/stable_hasher/tests.rs index 3eec9c9..470a183 100644 --- a/src/stable_hasher/tests.rs +++ b/src/stable_hasher/tests.rs @@ -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()); +}