Skip to content

hash_map::OccupiedEntry should provide original key back. #83642

@kevincox

Description

@kevincox

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    T-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions