indexmap icon indicating copy to clipboard operation
indexmap copied to clipboard

feat: add OccupiedEntry.get_entry_mut, VacantEntry.insert_entry

Open jhgg opened this issue 4 years ago • 3 comments

Adds 2 utility functions ontop of the Entry API.

  • OccupiedEntry.get_entry_mut - for when you want a reference to the key, and a mutable reference to the value.
  • VacantEntry.insert_entry - for when you want to insert into the map, and return a reference to the key, and a mutable reference to the value.

jhgg avatar Mar 27 '20 01:03 jhgg

Has anything like this been proposed for the std maps? Ideally, we would keep a compatible API, and these methods don't seem particular to IndexMap.

cuviper avatar Mar 27 '20 15:03 cuviper

No :( I just needed these for a project I'm working on - and felt like it'd be cool to upstream it here. I don't have the time to get these into std tho.

jhgg avatar Mar 27 '20 19:03 jhgg

A similar API was recently added to hashbrown: https://github.com/rust-lang/hashbrown/pull/145

glaebhoerl avatar Mar 28 '20 10:03 glaebhoerl