]> git.lizzy.rs Git - rust.git/blob - src/tools/clippy/src/docs/flat_map_option.txt
Auto merge of #101688 - cjgillot:verify-hir-parent, r=petrochenkov
[rust.git] / src / tools / clippy / src / docs / flat_map_option.txt
1 ### What it does
2 Checks for usages of `Iterator::flat_map()` where `filter_map()` could be
3 used instead.
4
5 ### Why is this bad?
6 When applicable, `filter_map()` is more clear since it shows that
7 `Option` is used to produce 0 or 1 items.
8
9 ### Example
10 ```
11 let nums: Vec<i32> = ["1", "2", "whee!"].iter().flat_map(|x| x.parse().ok()).collect();
12 ```
13 Use instead:
14 ```
15 let nums: Vec<i32> = ["1", "2", "whee!"].iter().filter_map(|x| x.parse().ok()).collect();
16 ```