Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wip: allow providing the key at insertion time for EntryRef #579

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

djugei
Copy link

@djugei djugei commented Oct 17, 2024

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.

@djugei djugei marked this pull request as draft October 17, 2024 08:09
@cuviper
Copy link
Member

cuviper commented Oct 17, 2024

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:

assert!(value.equivalent(&new), "new value is not equivalent");

src/map.rs Outdated Show resolved Hide resolved
src/map.rs Show resolved Hide resolved
@djugei
Copy link
Author

djugei commented Oct 18, 2024

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?

@cuviper
Copy link
Member

cuviper commented Oct 18, 2024

I'll defer to @Amanieu to decide on the API design.

@djugei
Copy link
Author

djugei commented Feb 5, 2025

i disagree with clippy on this one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants