summaryrefslogtreecommitdiffstats
path: root/src/tools/clippy/src/docs/manual_find.txt
blob: e3e07a2771f95ccc49ca7275e60c47c6edae29f2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
### What it does
Check for manual implementations of Iterator::find

### Why is this bad?
It doesn't affect performance, but using `find` is shorter and easier to read.

### Example

```
fn example(arr: Vec<i32>) -> Option<i32> {
    for el in arr {
        if el == 1 {
            return Some(el);
        }
    }
    None
}
```
Use instead:
```
fn example(arr: Vec<i32>) -> Option<i32> {
    arr.into_iter().find(|&el| el == 1)
}
```