]> git.lizzy.rs Git - rust.git/blob - src/docs/manual_find.txt
Auto merge of #9425 - kraktus:patch-1, r=xFrednet
[rust.git] / src / docs / manual_find.txt
1 ### What it does
2 Check for manual implementations of Iterator::find
3
4 ### Why is this bad?
5 It doesn't affect performance, but using `find` is shorter and easier to read.
6
7 ### Example
8
9 ```
10 fn example(arr: Vec<i32>) -> Option<i32> {
11     for el in arr {
12         if el == 1 {
13             return Some(el);
14         }
15     }
16     None
17 }
18 ```
19 Use instead:
20 ```
21 fn example(arr: Vec<i32>) -> Option<i32> {
22     arr.into_iter().find(|&el| el == 1)
23 }
24 ```