wip: allow providing the key at insertion time for EntryRef
Either explicitly through insert_kv or implicitly through insert_clone.
I have added an assert in insert_kv just to be sure, but if it is only a logic error to insert a different key at an entry or is caught deeper in the stack it should be removed/changed to debug_assert.
If this is something the maintainers are interested in i can implement the EntryRef and OccupiedEntryRef variants and document them.
I have added an assert in insert_kv just to be sure, but if it is only a logic error to insert a different key at an entry or is caught deeper in the stack it should be removed/changed to debug_assert.
I expect we do want a full assert, just like we did in HashSet::get_or_insert_with:
https://github.com/rust-lang/hashbrown/blob/eea980411a75c5229a562f9543fe1b035ad384c9/src/set.rs#L957
i think i will drop the insert_clone as insert_kv already covers the usecase. if passing the wrong item is just a logic error i do think that using debug_assert is the correct move, though it is somewhat likely for the compiler to be smart even about the full assert.
should i make the full pr?
I'll defer to @Amanieu to decide on the API design.
i disagree with clippy on this one.
@Amanieu can i get some feedback on the api design here? i would like to start depending on the main hashbrown again.
this saves clones when trying to insert in a loop.
EntryRef already has or_insert_with_key which is a bit of a name collision, so i am for now only adding the functionality to VacantEntryRef.
@Amanieu i have integrated the suggestions. Unsure if the docs are enough, i mainly point to the regular insert docs instead of duplicating.
This should be ready to merge now i think, i have rebased it on top of master.
expanded the comment by adding 2 doctests and added a descriptive panic message to the assert
I've cleaned up the doc comment a bit. Thanks for working on this!
oh yeah that is much better documentation!