pFad - Phone/Frame/Anonymizer/Declutterfier! Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

URL: https://doc.rust-lang.org/std/pin/../default/../rc/../../../../std/string/../hash/

ff2,SourceCodePro-Semibold-aa29a496.ttf.woff2".split(",").map(f=>``).join(""))

Module hash

Module hash 

1.0.0 · Source
Expand description

Generic hashing support.

This module provides a generic way to compute the hash of a value. Hashes are most commonly used with HashMap and HashSet.

The simplest way to make a type hashable is to use #[derive(Hash)]:

§Examples

use std::hash::{DefaultHasher, Hash, Hasher};

#[derive(Hash)]
struct Person {
    id: u32,
    name: String,
    phone: u64,
}

let person1 = Person {
    id: 5,
    name: "Janet".to_string(),
    phone: 555_666_7777,
};
let person2 = Person {
    id: 5,
    name: "Bob".to_string(),
    phone: 555_666_7777,
};

assert!(calculate_hash(&person1) != calculate_hash(&person2));

fn calculate_hash<T: Hash>(t: &T) -> u64 {
    let mut s = DefaultHasher::new();
    t.hash(&mut s);
    s.finish()
}

If you need more control over how a value is hashed, you need to implement the Hash trait:

use std::hash::{DefaultHasher, Hash, Hasher};

struct Person {
    id: u32,
    name: String,
    phone: u64,
}

impl Hash for Person {
    fn hash<H: Hasher>(&self, state: &mut H) {
        self.id.hash(state);
        self.phone.hash(state);
    }
}

let person1 = Person {
    id: 5,
    name: "Janet".to_string(),
    phone: 555_666_7777,
};
let person2 = Person {
    id: 5,
    name: "Bob".to_string(),
    phone: 555_666_7777,
};

assert_eq!(calculate_hash(&person1), calculate_hash(&person2));

fn calculate_hash<T: Hash>(t: &T) -> u64 {
    let mut s = DefaultHasher::new();
    t.hash(&mut s);
    s.finish()
}

Structs§

BuildHasherDefault
Used to create a default BuildHasher instance for types that implement Hasher and Default.
DefaultHasher
The default Hasher used by RandomState.
RandomState
RandomState is the default state for HashMap types.
SipHasherDeprecated
An implementation of SipHash 2-4.

Traits§

BuildHasher
A trait for creating instances of Hasher.
Hash
A hashable type.
Hasher
A trait for hashing an arbitrary stream of bytes.

Derive Macros§

Hash
Derive macro generating an impl of the trait Hash.
pFad - Phonifier reborn

Pfad - The Proxy pFad © 2024 Your Company Name. All rights reserved.





Check this box to remove all script contents from the fetched content.



Check this box to remove all images from the fetched content.


Check this box to remove all CSS styles from the fetched content.


Check this box to keep images inefficiently compressed and original size.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy