Hash/Hasher traits are really inconvenient

67 points vovanz

Let's suppose that I know something about my data that allows me to hash it very efficiently. Maybe I am working on an AI for an abstract board game and I want to implement Zobrist hashing.

At first I thought that I should write my own implementation of Hash trait, but then I realized that I can't just return whatever hash value I want. I still need to pass it to a Hasher!

Okay, maybe I just need to write my own Hasher? But Hasher doesn't allow me to write a hashing algorithm just for my type that I need to be hash. Hasher requires me to implement hashing for an arbitrary byte sequence which doesn't allow me leverage any knowledge about the best way to hash my data, because when the data reaches the Hasher I can't access it structure anymore, I can only see unstructured sequence of bytes.

Has anyone encountered a similar problem? Maybe there are some workarounds that I don't see or some crates that solve this issue somehow?