Closed
Description
Associative maps (HashMap
and BTreeMap
) in Rust are currently missing two methods to get owning iterators to their keys or values.
We have iter
to get key-value reference pairs, iter_mut
to get key-value mutable reference pairs and into_iter
to get owned key-value pairs.
I'd expect keys
and values
to offer a similar trio of methods (with an exception for keys_mut
of course). values_mut
is there, but the into
variants are missing for seemingly no good reason.
As an example implementation (but perhaps we can do better):
pub fn into_keys(self) -> impl Iterator<Item = K> {
self.into_iter().map(|(k, v)| k)
}
pub fn into_values(self) -> impl Iterator<Item = V> {
self.into_iter().map(|(k, v)| v)
}