rust/src/docs/map_clone.txt
2022-09-09 13:36:26 +02:00

22 lines
No EOL
424 B
Text

### What it does
Checks for usage of `map(|x| x.clone())` or
dereferencing closures for `Copy` types, on `Iterator` or `Option`,
and suggests `cloned()` or `copied()` instead
### Why is this bad?
Readability, this can be written more concisely
### Example
```
let x = vec![42, 43];
let y = x.iter();
let z = y.map(|i| *i);
```
The correct use would be:
```
let x = vec![42, 43];
let y = x.iter();
let z = y.cloned();
```