We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
map.iter().map(|(_,v)| v)
Warning to iterator operations that are equivalent to .keys() and .values().
.keys()
.values()
Similar lint: https://rust-lang.github.io/rust-clippy/stable/index.html#for_kv_map
iter_kv_map
style
Simpler and readable than the original code.
No response
let map = HashMap::new(); let keys = map.iter().map(|(key, _)| key).collect::<Vec<_>>(); let values = map.iter().map(|(_, value)| value).collect::<Vec<_>>();
Could be written as:
let map = HashMap::new(); let keys = map.keys().collect::<Vec<_>>(); let values = map.values().collect::<Vec<_>>();
The text was updated successfully, but these errors were encountered:
Just mentioning that the lint also works when the key or value is used to create another value.
key
value
For example, these two lines are equivalent:
map.iter().map(|(key, _)| key.to_uppercase()); map.keys().map(|key| key.to_uppercase());
Sorry, something went wrong.
@rustbot claim
481dc2e
kartva
Successfully merging a pull request may close this issue.
What it does
Warning to iterator operations that are equivalent to
.keys()
and.values()
.Similar lint: https://rust-lang.github.io/rust-clippy/stable/index.html#for_kv_map
Lint Name
iter_kv_map
Category
style
Advantage
Simpler and readable than the original code.
Drawbacks
No response
Example
Could be written as:
The text was updated successfully, but these errors were encountered: