diff options
Diffstat (limited to 'src/tools/clippy/src/docs/iter_kv_map.txt')
-rw-r--r-- | src/tools/clippy/src/docs/iter_kv_map.txt | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/src/tools/clippy/src/docs/iter_kv_map.txt b/src/tools/clippy/src/docs/iter_kv_map.txt new file mode 100644 index 000000000..a063c8195 --- /dev/null +++ b/src/tools/clippy/src/docs/iter_kv_map.txt @@ -0,0 +1,22 @@ +### 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<_>>(); +```
\ No newline at end of file |