]> git.lizzy.rs Git - rust.git/blob - src/docs/iter_with_drain.txt
Auto merge of #9421 - xphoniex:fix-#9420, r=giraffate
[rust.git] / src / docs / iter_with_drain.txt
1 ### What it does
2 Checks for use of `.drain(..)` on `Vec` and `VecDeque` for iteration.
3
4 ### Why is this bad?
5 `.into_iter()` is simpler with better performance.
6
7 ### Example
8 ```
9 let mut foo = vec![0, 1, 2, 3];
10 let bar: HashSet<usize> = foo.drain(..).collect();
11 ```
12 Use instead:
13 ```
14 let foo = vec![0, 1, 2, 3];
15 let bar: HashSet<usize> = foo.into_iter().collect();
16 ```