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

Add entry_ref API to HashMap #301

Merged
merged 3 commits into from
Dec 19, 2021
Merged

Add entry_ref API to HashMap #301

merged 3 commits into from
Dec 19, 2021

Conversation

ajtribick
Copy link
Contributor

An initial attempt at an entry_ref API to do the simple case that raw_entry_mut is used for. I basically attempted to mirror the existing entry API, but allow passing a borrowed version of the key. I left off mirroring the Send and Sync traits as I'm not sure what these should be.

The relationships I use between the key K and borrowed key Q is K: Borrow<Q> + From<&Q>. The reason for not using Q: ToOwned<K> is to support key types like Rc<str> (which is used in a couple of the doctests), which would not be possible with to_owned().

Hopefully this is somewhat useful.

Copy link
Member

@Amanieu Amanieu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work! I'm really glad to see this feature, it was much needed!

cc @rust-lang/libs-api since this API is likely to come to the standard library HashMap soon and I would like to iterate on the API within the hashbrown repo first.

src/map.rs Outdated
}

impl<'a, K, Q: ?Sized> KeyOrRef<'a, K, Q> {
pub fn into_owned(self) -> K
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

KeyOrRef is a private type, so this method doesn't need to be pub.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, updated.

@ajtribick
Copy link
Contributor Author

ajtribick commented Dec 13, 2021

I'm not sure why the update triggered the clippy warning for missing safety docs on the Allocator trait when the first version did not. Presumably the safety docs should be something like the ones at https://doc.rust-lang.org/nightly/core/alloc/trait.Allocator.html ?

@Amanieu
Copy link
Member

Amanieu commented Dec 13, 2021

It's most likely because CI always uses the latest rust nightly and this lint was recently added to clippy.

I think you can safely just disable this lint. This Allocator trait isn't exposed outside this crate anyways.

@ajtribick
Copy link
Contributor Author

Ok, lint is disabled. Regarding the Send and Sync implementations (presumably needed for OccupiedEntryRef), how should I implement these?

@Amanieu
Copy link
Member

Amanieu commented Dec 19, 2021

For Send: it requires that K,V,S,A are Send and that Q is Sync. This is because &T is Send if T: Sync.
For Sync: it requires that K,V,S,A,Q are `Sync.

@ajtribick
Copy link
Contributor Author

Thanks! Added the impls.

@Amanieu
Copy link
Member

Amanieu commented Dec 19, 2021

@bors r+

@bors
Copy link
Contributor

bors commented Dec 19, 2021

📌 Commit 7c545e1 has been approved by Amanieu

@bors
Copy link
Contributor

bors commented Dec 19, 2021

⌛ Testing commit 7c545e1 with merge 898a9fe...

@bors
Copy link
Contributor

bors commented Dec 19, 2021

☀️ Test successful - checks-actions
Approved by: Amanieu
Pushing 898a9fe to master...

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.

3 participants