Skip to main content

Module hash

Module hash 

Source
Expand description

A hash of a game’s state, the same on every platform and every run: what a replay compares step by step to find where two runs part, and what two machines playing one game can exchange to find a desync.

state_hash feeds any Serialize value to a 64-bit FNV-1a hash in a fixed form of this file’s own: every value is a tag byte and its bytes, integers little-endian at a fixed width, strings and byte strings with their length, sequences, maps and structs closed by an end byte, variants by their index. So the form never depends on a dependency’s version or on the platform, and two different values of one type never have the same form. Field and type names are left out: renaming a field keeps a state’s hash; reordering fields changes it.

A state hashes the same each run only if it serializes the same: its maps must be ordered (BTreeMap), never a hash map whose order changes from run to run.

Structs§

HashError
Why a state could not be hashed: its own Serialize refused, with this message.
StateHash
The hash of a state (state_hash).

Functions§

state_hash
The hash of value (module docs).