Description
As discussed at Why does str.hash(…)
pass an extra byte to the Hasher?: the code of impl Hash for &str
specifically passes an extra 0xFF byte to the Hasher, so that values like ("ab", "c")
and ("a", "bc")
hash differently (added in 6066118).
This is a subtle property of hashing and should probably be mentioned in the documentation for Hash
— particularly as the documentation for Hasher
already says “you cannot assume, for example, that a write_u32
call is equivalent to four calls of write_u8
” which could be sloppily interpreted as an expectation that a good Hasher
implementation will handle “quoting” of sequential calls itself.
If an implementor of Hash
fails to have this property, it could compromise the hash-DoS resistance that Rust tries to offer by default.
@rustbot labels: +A-docs +T-libs-api +C-enhancement