You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
#132 added usize-based indexing for the values in an IndexMap, which is absolutely the correct behavior for Index<usize> to have. However, sometimes I want to get either just the key or a key-value pair at a particular index, and get_index is a verbose way to do that if I know the index is valid. A possible alternate spelling would be map.keys()[idx], implemented by providing Index<usize> on Keys.
Of course, this particular approach means that indexing would be valid even after consuming some of the keys, even if that's not the recommended use, and the code needs to decide and document what that means.
The text was updated successfully, but these errors were encountered:
Of course, this particular approach means that indexing would be valid even after consuming some of the keys, even if that's not the recommended use, and the code needs to decide and document what that means.
Since Keys is a wrapper around slice::Iter, I think the only thing we can currently do is index the remaining contents. Maybe we could change that wrapper, but note that Slice::keys() also feeds into this. I think indexing the current state of the iterator makes the most sense.
I feel a little hesitation about slippery-slope precedent here... e.g. does this make sense for IntoKeys too? What about the value iterators? But... maybe it's ok for Keys alone to serve as both an indexable "view" and an iterator.
#132 added usize-based indexing for the values in an IndexMap, which is absolutely the correct behavior for
Index<usize>
to have. However, sometimes I want to get either just the key or a key-value pair at a particular index, andget_index
is a verbose way to do that if I know the index is valid. A possible alternate spelling would bemap.keys()[idx]
, implemented by providingIndex<usize>
on Keys.Of course, this particular approach means that indexing would be valid even after consuming some of the keys, even if that's not the recommended use, and the code needs to decide and document what that means.
The text was updated successfully, but these errors were encountered: