Hi all,
Is the code below a proper way to retrieve an original key from a HashMap?
In a few derived HashMaps, I use references to keys living in a mother HashMap. Just creating a ref to a newly created key-value does not work because it goes out of scope in no time: this does not work:
{
...
auxmap.insert(&Location::new(value_x, value_y), newValue)
...
}
This compiles (reduced code):
{
...
let key = *auxmap.get_key_value(&Location::new(value_x, value_y)).unwrap().0;
auxmap.insert(key, newValue);
...
}
Is this remotely idiomatic?
Is HashMap::entry() the way to go, knowing my key exists? entry() seems to be meant for use cases where key existence is not known in advance.
Should I just use clones of the key values (Location {x: i32, y: i32}) and thus avoid this problem?
Thanks.