I would like to have a hash map with an owned multi-string key that I can query efficiently. For single-string keys, the
K: Borrow<Q> bounds on
get() make it so that I can query
String keys with
&str values, but I'm struggling to figure out to make this work for 2-string keys.
The problem I'm running into is that while the invariants for
Hash equivalence) should be good enough, the definition of
Borrow requires that
borrow() returns a reference into self. So while I think
(&str, &str) (or a tuple struct verion of this) technically fits all the requirements for being used to query
(String, String), I can't see a way to make this work.
I've also tried defining my own
Cow-like enum, which runs into trouble when I want to define
impl Borrow<Key<'a>> for Key<'static> because this conflicts with an std implementation.
An alternative solution would be concatenating the key's strings together into a single string, but this would require an allocation per query at least in the general case.
Am I missing something? What's the best way to do this?