AddressHash

Derive Macro AddressHash 

Source
#[derive(AddressHash)]
Expand description

Derives Hash based on memory addresses.

By deriving AddressHash, the Hash trait will automatically be implemented for the given type. The implementation will use a given instance’s address in memory in when performing hashing.

Note that since implementations of Hash and Eq must agree, it is recommended to derive both AddressHash and AddressEq together.

use address_cmp::{AddressEq, AddressHash};
use std::collections::HashSet;

#[derive(AddressHash, AddressEq)]
enum Animal {
    Bat,
    Cat,
}

let mut set = HashSet::new();
let a1 = Animal::Bat;
let a2 = Animal::Cat;
let a3 = Animal::Bat;

set.insert(a1);
set.insert(a2);
set.insert(a3);

assert_eq!(set.len(), 3);