#hash #stable #backward #compatibility #structured #hashing #value

stable-hash

A stable, structured hash with backward compatibility

7 releases

0.4.3 Nov 4, 2022
0.4.2 Jun 22, 2022
0.4.1 Mar 29, 2022
0.3.3 Jun 22, 2022
0.3.1 Feb 4, 2022

#798 in Algorithms

Download history 524/week @ 2024-01-02 394/week @ 2024-01-09 574/week @ 2024-01-16 392/week @ 2024-01-23 740/week @ 2024-01-30 591/week @ 2024-02-06 558/week @ 2024-02-13 372/week @ 2024-02-20 676/week @ 2024-02-27 731/week @ 2024-03-05 783/week @ 2024-03-12 716/week @ 2024-03-19 614/week @ 2024-03-26 321/week @ 2024-04-02 804/week @ 2024-04-09 658/week @ 2024-04-16

2,758 downloads per month
Used in 3 crates (2 directly)

MIT license

45KB
914 lines

This crate provides a stable, structured hash with backward compatibility features. What does that mean?

  • Stable: The value of the hash will not change across minor versions of this library, even when the compiler, process, architecture, or std lib does change.
  • Structured: Hashes structs, rather than streams
  • Backward compatibility: It is possible to make limited changes to a struct's schema without changing the value of the hash. One change is that you can add new fields. This is accomplished by skipping default values when hashing. For example, the values None, 0, false, and vec![] do not contribute to the hash. Therefore structs Old { a: 1 } and New { a: 1, b: None } hash to the same value. Another feature enabling backward compatibility is that the size of an integer can be increased without changing the value. For example, Old { a: 1u16 } and New { a: 1u32 } hash to the same value. Note that even though two structs with different schemas are allowed to collide, two structs with the same schema never collide (where collide is defined as contribution to the hash is injective in respect to the encoding. It is still possible to find collisions in the final output, especially for the non-cryptographic version)

Dependencies

~3MB
~72K SLoC