elsa
elsa copied to clipboard
Give back references to keys
FrozenMap hands out references to its values, but since the map also owns the keys it is possible to provide references to the keys as well.
Assuming K: StableDeref, implement:
fn insert_key_value(self, k: K, v: V) -> (&K::Target, &V::Target);
fn get_key_value(…) -> (&K::Target, &V::Target);
Ought to be fine as long as we appropriately guard things
There's a PR for get_key_value at #35.
I couldn't do insert_key_value, getting a key with the map lifetime from hash_map::Entry can't be done in one go / without cloning, see https://github.com/rust-lang/rust/issues/65225#issuecomment-1066442440 “On the topic of key ownership…” for a discussion on what needs to be done before something like that could be stabilized.
OccupiedEntry needs to keep a non-Optional reference to the key within the map.