RS.CLIPPY.ITER_KV_MAP
Iterating on map using `iter` when `keys` or `values` would do
This checker is a Clippy lint created by The Rust Project Contributors. The documentation shown here is a copy of the original documentation for: iter_kv_map. Copyright ©2025 The Rust Team. All rights reserved.
What it does
Checks for iterating a map (HashMap or BTreeMap) and
ignoring either the keys or values.
Why is this bad?
Readability. There are keys and values methods that
can be used to express that we only need the keys or the values.
Example
let map: HashMap<u32, u32> = HashMap::new();
let values = map.iter().map(|(_, value)| value).collect::<Vec<_>>();
Use instead:
let map: HashMap<u32, u32> = HashMap::new();
let values = map.values().collect::<Vec<_>>();
Configuration
-
msrv: The minimum rust version that the project supports. Defaults to therust-versionfield inCargo.toml(default:
current version)