-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Closed
Labels
A-collectionsArea: `std::collections`Area: `std::collections`A-iteratorsArea: IteratorsArea: IteratorsC-feature-acceptedCategory: A feature request that has been accepted pending implementation.Category: A feature request that has been accepted pending implementation.T-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.Relevant to the library API team, which will review and decide on the PR/issue.
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)
}
Enet4, AndrewKvalheim, ericclone, Globidev, askoretskiy and 3 more
Metadata
Metadata
Assignees
Labels
A-collectionsArea: `std::collections`Area: `std::collections`A-iteratorsArea: IteratorsArea: IteratorsC-feature-acceptedCategory: A feature request that has been accepted pending implementation.Category: A feature request that has been accepted pending implementation.T-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.Relevant to the library API team, which will review and decide on the PR/issue.