]> git.lizzy.rs Git - rust.git/blob - src/docs/iter_kv_map.txt
Add iter_kv_map lint
[rust.git] / src / docs / iter_kv_map.txt
1 ### What it does
2
3 Checks for iterating a map (`HashMap` or `BTreeMap`) and
4 ignoring either the keys or values.
5
6 ### Why is this bad?
7
8 Readability. There are `keys` and `values` methods that
9 can be used to express that we only need the keys or the values.
10
11 ### Example
12
13 ```
14 let map: HashMap<u32, u32> = HashMap::new();
15 let values = map.iter().map(|(_, value)| value).collect::<Vec<_>>();
16 ```
17
18 Use instead:
19 ```
20 let map: HashMap<u32, u32> = HashMap::new();
21 let values = map.values().collect::<Vec<_>>();
22 ```