-
Notifications
You must be signed in to change notification settings - Fork 159
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Add more Vec/slice-like methods to maps and sets #160
Conversation
|
src/map.rs
Outdated
self.as_entries().first().map(Bucket::refs) | ||
} | ||
|
||
pub fn first_mut(&mut self) -> Option<(&mut K, &mut V)> { |
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.
If you agree I'd do &K here, that's the initial interface we were going for in this crate (while still allowing opt-in access to mutable keys with the trait). Implementing a such "first_mut2" in MutableKeys could be done on a YAGNI basis 🙂
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.
Comment about &K applies
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 guess I technically can't approve while there are still methods without doc comment, but I like the idea.
OK, I added more docs for the public methods. At some point we should probably go for |
Oh, I switched to |
```rust impl<K, V, S> IndexMap<K, V, S> { pub fn truncate(&mut self, len: usize); pub fn split_off(&mut self, at: usize) -> Self where S: Clone; pub fn first(&self) -> Option<(&K, &V)>; pub fn first_mut(&mut self) -> Option<(&mut K, &mut V)>; pub fn last(&self) -> Option<(&K, &V)>; pub fn last_mut(&mut self) -> Option<(&mut K, &mut V)>; pub fn swap_indices(&mut self, a: usize, b: usize); } impl<T, S> IndexSet<T, S> { pub fn truncate(&mut self, len: usize); pub fn split_off(&mut self, at: usize) -> Self where S: Clone; pub fn first(&self) -> Option<&T>; pub fn last(&self) -> Option<&T>; pub fn swap_indices(&mut self, a: usize, b: usize); } ``` I would prefer `&K` instead of `&mut K` in `IndexMap::first_mut` and `last_mut`, but this is consistent with the existing `get_index_mut`.
I would prefer
&K
instead of&mut K
inIndexMap::first_mut
andlast_mut
, but this is consistent with the existingget_index_mut
.