]> git.lizzy.rs Git - rust.git/blob - src/docs/iter_on_single_items.txt
Auto merge of #9421 - xphoniex:fix-#9420, r=giraffate
[rust.git] / src / docs / iter_on_single_items.txt
1 ### What it does
2
3 Checks for calls to `iter`, `iter_mut` or `into_iter` on collections containing a single item
4
5 ### Why is this bad?
6
7 It is simpler to use the once function from the standard library:
8
9 ### Example
10
11 ```
12 let a = [123].iter();
13 let b = Some(123).into_iter();
14 ```
15 Use instead:
16 ```
17 use std::iter;
18 let a = iter::once(&123);
19 let b = iter::once(123);
20 ```
21
22 ### Known problems
23
24 The type of the resulting iterator might become incompatible with its usage