File tree Expand file tree Collapse file tree 2 files changed +22
-0
lines changed Expand file tree Collapse file tree 2 files changed +22
-0
lines changed Original file line number Diff line number Diff line change @@ -88,6 +88,7 @@ pub trait ExtendedHasher: Hasher {
8888/// let hash: Hash128 = hasher.finish();
8989/// ```
9090#[ must_use]
91+ #[ derive( Clone ) ]
9192pub struct StableHasher < H : ExtendedHasher > {
9293 state : H ,
9394}
Original file line number Diff line number Diff line change @@ -112,3 +112,24 @@ fn test_isize_compression() {
112112 check_hash ( 0xFF , 0xFFFFFFFFFFFFFFFF ) ;
113113 check_hash ( u64:: MAX /* -1 */ , 1 ) ;
114114}
115+
116+ #[ test]
117+ fn test_cloned_hasher_output ( ) {
118+ // Test that integers are handled consistently across platforms.
119+ let test_u8 = 0xAB_u8 ;
120+ let test_u16 = 0xFFEE_u16 ;
121+ let test_u32 = 0x445577AA_u32 ;
122+
123+ let mut h1 = StableSipHasher128 :: new ( ) ;
124+ test_u8. hash ( & mut h1) ;
125+ test_u16. hash ( & mut h1) ;
126+
127+ let h2 = h1. clone ( ) ;
128+ let mut h3 = h1. clone ( ) ;
129+ // Make sure the cloned hasher can be fed more values.
130+ test_u32. hash ( & mut h3) ;
131+
132+ let h1_hash: TestHash = h1. finish ( ) ;
133+ assert_eq ! ( h1_hash, h2. finish( ) ) ;
134+ assert_ne ! ( h1_hash, h3. finish( ) ) ;
135+ }
You can’t perform that action at this time.
0 commit comments