RS.CLIPPY.FLAT_MAP_OPTION
Used `flat_map` where `filter_map` could be used instead
This checker is a Clippy lint created by The Rust Project Contributors. The documentation shown here is a copy of the original documentation for: flat_map_option. Copyright ©2025 The Rust Team. All rights reserved.
What it does
Checks for usage of Iterator::flat_map() where filter_map() could be
used instead.
Why is this bad?
filter_map() is known to always produce 0 or 1 output items per input item,
rather than however many the inner iterator type produces.
Therefore, it maintains the upper bound in Iterator::size_hint(),
and communicates to the reader that the input items are not being expanded into
multiple output items without their having to notice that the mapping function
returns an Option.
Example
let nums: Vec<i32> = ["1", "2", "whee!"].iter().flat_map(|x| x.parse().ok()).collect();
Use instead:
let nums: Vec<i32> = ["1", "2", "whee!"].iter().filter_map(|x| x.parse().ok()).collect();