#hash #reference #rc #identity #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

#87 in #rc

Download history 1/week @ 2024-07-24 8/week @ 2024-07-31 8/week @ 2024-08-07 8/week @ 2024-08-14 6/week @ 2024-08-21 1/week @ 2024-09-11 22/week @ 2024-09-18 191/week @ 2024-09-25 278/week @ 2024-10-02 389/week @ 2024-10-09 231/week @ 2024-10-16 191/week @ 2024-10-23 158/week @ 2024-10-30 188/week @ 2024-11-06

793 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