Skip to content

Feature: OccupiedEntry::into_key #678

@Imberflur

Description

@Imberflur

I have a method that takes a value, creates a new key, inserts those into the map, and returns the key to the caller. I can't find a way to just return a reference to the key since the reference from OccupiedEntry::key can't outlive the current function. In this situation, it seems like I need to either clone the key or return the whole OccupiedEntry.

It seems like I could solve this if OccupiedEntry had an into_key method be that consumes the entry and returns a reference to the key with the lifetime of the original borrow from the hashmap (like OccupiedEntry::into_mut does for the value). Is this a reasonable solution? Is there a reason this can't exist or an existing way to achieve this? I wasn't able to find anything on the topic from searching existing issues.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions