Using transmute to cast away lifetime constraints


#1

I am trying to create a StringInterner for a bidirectional mapping between String and an indexable type,
such as can be found in the Rust compile for the symbol table implementation.
The goal is to create it with as low memory overhead as possibru.

This implementation works and satisfies its unit-tests. However, I am feeling dirty for this unidiomatic code.

Is there a more idiomatic way to do this in Rust?


#2

You could use the hash of the str as index.


#3

I asked in the IRC channel as well and after a while we came up with the following:

In this solution the HashMap maps from InternalStrRef which is a tight wrapper around *const str instances.
I was even able to find a bug with my former implementation!

Can you elaborate further how hashes as external indices could work?