The official docs of iter::flatten states :
An iterator that flattens one level of nesting in an iterator of things that can be turned into iterators.
But for this code:
if let Ok(entries) = fs::read_dir("/path/to/dir") {
for entry in entries {
if let Ok(entry) = entry {
// Do something
}
}
}
Clippy suggests to use entries.flatten()
instead of if-let
block, But here "nesting" is not there, instead it's an Iterator of Results. "Nesting" would look like an Iterator of Iterators.
There's no exclusive flatten()
method implementation in ReadDir which is returned by fs::read_dir()
So my question is what exactly flatten do here? How does it work?