]> git.proxmox.com Git - rustc.git/blame - src/tools/clippy/src/docs/flat_map_option.txt
New upstream version 1.66.0+dfsg1
[rustc.git] / src / tools / clippy / src / docs / flat_map_option.txt
CommitLineData
f2b60f7d
FG
1### What it does
2Checks for usages of `Iterator::flat_map()` where `filter_map()` could be
3used instead.
4
5### Why is this bad?
6When applicable, `filter_map()` is more clear since it shows that
7`Option` is used to produce 0 or 1 items.
8
9### Example
10```
11let nums: Vec<i32> = ["1", "2", "whee!"].iter().flat_map(|x| x.parse().ok()).collect();
12```
13Use instead:
14```
15let nums: Vec<i32> = ["1", "2", "whee!"].iter().filter_map(|x| x.parse().ok()).collect();
16```