BuildHasherDefault in std::hash - Rust (original) (raw)

Struct BuildHasherDefault

1.0.0 · Source

pub struct BuildHasherDefault<H>(/* private fields */);

Expand description

Used to create a default BuildHasher instance for types that implementHasher and Default.

BuildHasherDefault<H> can be used when a type H implements Hasher andDefault, and you need a corresponding BuildHasher instance, but none is defined.

Any BuildHasherDefault is zero-sized. It can be created withdefault. When using BuildHasherDefault with HashMap orHashSet, this doesn’t need to be done, since they implement appropriateDefault instances themselves.

§Examples

Using BuildHasherDefault to specify a custom BuildHasher forHashMap:

use std::collections::HashMap;
use std::hash::{BuildHasherDefault, Hasher};

#[derive(Default)]
struct MyHasher;

impl Hasher for MyHasher {
    fn write(&mut self, bytes: &[u8]) {
        // Your hashing algorithm goes here!
       unimplemented!()
    }

    fn finish(&self) -> u64 {
        // Your hashing algorithm goes here!
        unimplemented!()
    }
}

type MyBuildHasher = BuildHasherDefault<MyHasher>;

let hash_map = HashMap::<u32, u32, MyBuildHasher>::default();

Source§

1.85.0 (const: 1.85.0) · Source

Creates a new BuildHasherDefault for Hasher H.

1.7.0 · Source§

1.7.0 · Source§

1.9.0 · Source§

1.7.0 · Source§

1.29.0 · Source§

Source§

Tests for self and other values to be equal, and is used by ==.

1.0.0 · Source§

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.

1.29.0 · Source§

§

§

§

§

§

§