Hash

The Hash trait enables a data value to be used as a key in several of Rust's standard library data structures, such as HashMap and HashSet.

Deriving the Hash trait looks like this:

#[derive(Hash)]
pub enum HashExample {
Good,
Bad,
}

While Eq and PartialEq are not actually required to implement Hash, if they are implemented, they need to agree with it, which is to say that if two values are equal, their hash values should also be equal. The automatically generated implementations have this property, so we only need to worry about it if we're doing manual implementations.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.191.181.252