-
Notifications
You must be signed in to change notification settings - Fork 320
Add hash_table::IterUnsafeMut, iter() method to various iterators
#667
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
base: master
Are you sure you want to change the base?
Conversation
| /// // Even though the key is mutably borrowed here, this is sound | ||
| /// // because we never actually mutate the key before yielding the | ||
| /// // immutable reference | ||
| /// let (ref key, ref mut val) = self.inner.next()?; | ||
| /// Some((key, val)) |
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.
Since this is just an example, and not part of the actual implementation, I chose to use a clearer implementation instead of the one we actually use.
68222f6 to
3f35627
Compare
3f35627 to
e2a7538
Compare
|
Rather than adding a whole new iterator kind, would it make more sense to direct users that need custom variance to the bucket iterator instead? |
|
That wouldn't really work because you would then need to mutably borrow the entire table inside the iterator, alongside the bucket iterator, to make it work, which would then give the same variance as Also because you might be confusing the raw bucket API with the one for |
Both of these would be useful for #666, and presumably other downstream hash table implementations.
First, the
iter()methods make it possible to implement downstreamDebugimplementations more easily, by letting iterators likeDrainbe paused and viewed immutably.Second, the new
iter_unsafe_mutmethod and correspondingIterUnsafeMutexists to make implementinghash_map::IterMuta bit more reasonable without being as unsafe. The struct docs should hopefully make its existence clear, but I would definitely love some extra scrutiny on that.