#rc #reference #hash #identity #hash-key #reference-identity

hash_by_ref

A simple NewType that wraps Rc<T> and allows to use the reference identity/pointer value of Rc<T> as keys in hashmap

1 unstable release

Uses old Rust 2015

0.1.0 Jun 23, 2017

#23 in #hash-key

Download history 158/week @ 2024-10-30 205/week @ 2024-11-06 194/week @ 2024-11-13 328/week @ 2024-11-20 156/week @ 2024-11-27 133/week @ 2024-12-04 305/week @ 2024-12-11 228/week @ 2024-12-18 126/week @ 2024-12-25 173/week @ 2025-01-01 140/week @ 2025-01-08 207/week @ 2025-01-15 355/week @ 2025-01-22 255/week @ 2025-01-29 303/week @ 2025-02-05 378/week @ 2025-02-12

1,361 downloads per month

Custom license

4KB
74 lines

HashByRef

This is a small helper crate to use Rc<T> as hash keys where equality is supposed to be determined by the underlaying reference identity (i.e. by the value of the pointer). It provides a type HashByRef<T> that can be used as key in the hashmap.

Quick Start

hash_by_ref = "0.1.0"
    use std::collections::HashMap;
    use std::rc::Rc;
    use hash_by_ref::HashByRef;

    let r1 = Rc::new(1);
    let r2 = Rc::new(1);
    let r3 = r1.clone();
    let mut h = HashMap::new();
    h.insert(HashByRef::new(r1.clone()),1);
    h.insert(HashByRef::new(r2.clone()),2);
    assert_eq!(h[&HashByRef::new(r1.clone())], 1);
    assert_eq!(h[&HashByRef::new(r2.clone())], 2);
    assert_eq!(h[&HashByRef::new(r3.clone())], 1);

No runtime deps