]> git.lizzy.rs Git - rust.git/blob - src/docs/from_iter_instead_of_collect.txt
Auto merge of #9475 - Nemo157:mod-files-remap, r=xFrednet
[rust.git] / src / docs / from_iter_instead_of_collect.txt
1 ### What it does
2 Checks for `from_iter()` function calls on types that implement the `FromIterator`
3 trait.
4
5 ### Why is this bad?
6 It is recommended style to use collect. See
7 [FromIterator documentation](https://doc.rust-lang.org/std/iter/trait.FromIterator.html)
8
9 ### Example
10 ```
11 let five_fives = std::iter::repeat(5).take(5);
12
13 let v = Vec::from_iter(five_fives);
14
15 assert_eq!(v, vec![5, 5, 5, 5, 5]);
16 ```
17 Use instead:
18 ```
19 let five_fives = std::iter::repeat(5).take(5);
20
21 let v: Vec<i32> = five_fives.collect();
22
23 assert_eq!(v, vec![5, 5, 5, 5, 5]);
24 ```