Skip to content

find_or_insert_with should return a &mut pointer #6394

Closed
@metajack

Description

@metajack

Trying to satisfy the borrow checker in some cases leads to a little bit clumsy HashMap code. For example, if you want to find_or_insert but need to modify the value.

Here's an example where I had to work around this by using contains_key and then find_mut and insert directly:

https://gist.github.com/metajack/5555485#file-gistfile2-diff-L28-L45

I suggest adding find_or_insert_mut and find_or_insert_with_mut. It might be better to use find_mut_or_insert and find_mut_or_insert_with as names perhaps.

Metadata

Metadata

Assignees

No one assigned

    Labels

    E-easyCall for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions