Trait BuildHasher
trait BuildHasher
A trait for creating instances of Hasher.
A BuildHasher is typically used (e.g., by HashMap) to create
Hashers for each key such that they are hashed independently of one
another, since Hashers contain state.
For each instance of BuildHasher, the Hashers created by
build_hasher should be identical. That is, if the same stream of bytes
is fed into each hasher, the same output will also be generated.
Examples
use ;
let s = new;
let mut hasher_1 = s.build_hasher;
let mut hasher_2 = s.build_hasher;
hasher_1.write_u32;
hasher_2.write_u32;
assert_eq!;
Associated Types
type Hasher: TraitBound { trait_: Path { path: "Hasher", id: Id(832), args: None }, generic_params: [], modifier: None }Type of the hasher that will be created.
Required Methods
fn build_hasher(self: &Self) -> <Self as >::HasherCreates a new hasher.
Each call to
build_hasheron the same instance should produce identicalHashers.Examples
use ; let s = new; let new_s = s.build_hasher;
Provided Methods
fn hash_one<T: Hash>(self: &Self, x: T) -> u64 where Self: Sized, <Self as >::Hasher: HasherCalculates the hash of a single value.
This is intended as a convenience for code which consumes hashes, such as the implementation of a hash table or in unit tests that check whether a custom
Hashimplementation behaves as expected.This must not be used in any code which creates hashes, such as in an implementation of
Hash. The way to create a combined hash of multiple values is to callHash::hashmultiple times using the sameHasher, not to call this method repeatedly and combine the results.Example
use ; use ; ; // Then later, in a `#[test]` for the type... let bh = new; assert_eq!; assert_eq!;
Implementors
impl<H: Default + Hasher> BuildHasher for BuildHasherDefault<H>