My understanding is that when .entry() returns Occupied the key provided is not used as the key was already in the map. There should then be a way to get the original key back. The current workaround is .key().clone() if they key type is clonable.
The following APIs could have an alternate version that provided the original key:
Now it may not make sense to add alternatives to all of these but it should be considered. Alternatives would be infeasible such as adding a key member to OccupiedEntry or making Entry::Occupied(OccupiedEntry, K).
The best way to do this isn't clear, but it would be nice to be able to work with non-clonable types and avoid unnecessary clones.
My understanding is that when
.entry()returnsOccupiedthe key provided is not used as the key was already in the map. There should then be a way to get the original key back. The current workaround is.key().clone()if they key type is clonable.The following APIs could have an alternate version that provided the original key:
Now it may not make sense to add alternatives to all of these but it should be considered. Alternatives would be infeasible such as adding a key member to
OccupiedEntryor makingEntry::Occupied(OccupiedEntry, K).The best way to do this isn't clear, but it would be nice to be able to work with non-clonable types and avoid unnecessary clones.