File tree Expand file tree Collapse file tree 1 file changed +5
-2
lines changed
Expand file tree Collapse file tree 1 file changed +5
-2
lines changed Original file line number Diff line number Diff line change @@ -41,9 +41,12 @@ assert_eq!(a.as_ptr(), b.as_ptr());
4141
4242` &BorrowedInterned ` can be used with hash-maps
4343
44+ Note that the pointer is being used for hashing and comparing (see ` Hash ` and ` PartialEq ` trait implementations)\
45+ as opposed to hashing and comparing the actual data - because the pointers are unique for the same data as long as it "lives" in memory
46+
4447``` rust
4548
46- let map = HashMap :: <Interned , u64 >:: from_iter ([(b " key" . as_ref () . into ( ), 1 )]);
49+ let map = HashMap :: <Interned , u64 >:: from_iter ([(Interned :: new ( b " key" ), 1 )]);
4750
4851let key = Interned :: new (b " key" );
4952assert_eq! (map . get (& key ), Some (& 1 ));
@@ -56,7 +59,7 @@ assert_eq!(map.get(borrowed_key), Some(&1));
5659
5760``` rust
5861
59- let map = BTreeMap :: <Interned , u64 >:: from_iter ([(b " key" . as_ref () . into ( ), 1 )]);
62+ let map = BTreeMap :: <Interned , u64 >:: from_iter ([(Interned :: new ( b " key" ), 1 )]);
6063
6164let key = Interned :: new (b " key" );
6265assert_eq! (map . get (& key ), Some (& 1 ));
You can’t perform that action at this time.
0 commit comments