Function hash

Source
pub fn hash<T: Display + ?Sized, H: Hasher>(hashee: &T, hasher: &mut H)
Expand description

Hashes a value with respect to its Display representation.

This satisfies the same property as hashee.to_string().hash(hasher) without heap allocation, although the exact hash values are not guaranteed to match. In particular, the following variant of Hash trait’s property holds:

format!("{}", k1) == format!("{}", k2) -> hash(k1) == hash(k2)

§Note

The Display implementation may not return error as described by the documentation of std::fmt. Doing so would result in an unspecified hash value or might even cause a panic in a future version.