Skip to content

HashMap::get_key_value_mut? #144

Closed
@dodomorandi

Description

@dodomorandi

I found myself needing a partially mutable version of HashMap::get_key_value, with the following signature:

pub fn get_key_value_mut<Q: ?Sized>(&mut self, k: &Q) -> Option<(&K, &mut V)> where
    K: Borrow<Q>,
    Q: Hash + Eq, 

Obviously I was looking at std, and I think I cannot obtain nothing similar without the unstable hash_raw_entry API. However, hashbrown currently supports the API, therefore it should be pretty straightforward to implement the new feature.

The only thing I am still doubtful is the possibility of creating of an inconsistent state with the proposed API. At first glance, it should not be possible to smash the state of the hashmap, but maybe I am missing something. What do you think?

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