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
It would be handy if IndexMap<K,V> and IndexSet<K> had a common trait that would let us iterate the keys of either and obtain their indices, like the keySet() method of Java maps. It might also sometimes be useful to be able to create a mutable set view of an IndexMap<K,V> by specifying a function that would produce values for new keys. Why not call these traits IndexKeys<K> and IndexKeysMut<K> respectively, and implement keys_as_set(&self) and keys_as_set_mut(&mut self, new_value_provider: Fn(&K) -> V) methods to provide the set views of a map? (IndexSet<K> would just implement them itself.)
The text was updated successfully, but these errors were encountered:
We have separate iterators, IndexMap::keys and regular IndexSet::iter, and you can enumerate() either of those to get their indices too, but what be the gain in having a common trait? If you have generic code that wants the keys, I would just have that take the input directly as an iterator.
Mutability is touchier, because we don't generally allow that, although there's some opt-in available by importing map::MutableKeys (which has iter_mut2) or set::MutableValues (no iterator yet).
It would be handy if
IndexMap<K,V>
andIndexSet<K>
had a common trait that would let us iterate the keys of either and obtain their indices, like thekeySet()
method of Java maps. It might also sometimes be useful to be able to create a mutable set view of anIndexMap<K,V>
by specifying a function that would produce values for new keys. Why not call these traitsIndexKeys<K>
andIndexKeysMut<K>
respectively, and implementkeys_as_set(&self)
andkeys_as_set_mut(&mut self, new_value_provider: Fn(&K) -> V)
methods to provide the set views of a map? (IndexSet<K>
would just implement them itself.)The text was updated successfully, but these errors were encountered: