RS.CLIPPY.ITER_ON_SINGLE_ITEMS
Iterator for array of length 1
This checker is a Clippy lint created by The Rust Project Contributors. The documentation shown here is a copy of the original documentation for: iter_on_single_items. Copyright ©2025 The Rust Team. All rights reserved.
What it does
Checks for calls to iter, iter_mut or into_iter on collections containing a single item
Why is this bad?
It is simpler to use the once function from the standard library:
Example
let a = [123].iter();
let b = Some(123).into_iter();
Use instead:
use std::iter;
let a = iter::once(&123);
let b = iter::once(123);
Known problems
The type of the resulting iterator might become incompatible with its usage