-
Notifications
You must be signed in to change notification settings - Fork 292
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
base: master
Are you sure you want to change the base?
Conversation
I expect we do want a full assert, just like we did in Line 957 in eea9804
|
pub fn insert_kv(self, key: K, value: V) -> &'map mut V | ||
where | ||
K: Hash, | ||
for<'k> &'k K: PartialEq<&'key Q>, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this should use Q: Equivalent<K>
instead, just like entry_ref
did when it was created.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah yes that covers exactly what is needed there. had not seen that trait so far and tbh i have not read a lot of hashbrowns code, i just needed one of those methods to avoid either copying my key more than needed or doing a double lookup.
where | ||
K: Hash + From<&'b Q>, | ||
K: Hash + From<&'key Q>, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not your problem, but this is an issue too, since downstream Q
might implement a bad From<&Q> for K
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah i noticed that too, that was half the reason i asked about the assert
i think i will drop the insert_clone as insert_kv already covers the usecase. should i make the full pr? |
I'll defer to @Amanieu to decide on the API design. |
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.