Skip to content

Add a function to get the key from a HashMap #43143

Closed
@iqualfragile

Description

@iqualfragile

Basically just

pub fn get_both<Q: ?Sized>(&self, k: &Q) -> Option<(&K,&V)>
        where K: Borrow<Q>,
              Q: Hash + Eq
    {
        self.search(k).into_occupied_bucket().map(|bucket| bucket.into_refs())
}

sometimes you need a reference to a key with the lifetime of the collection.

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-feature-acceptedCategory: A feature request that has been accepted pending implementation.T-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions