Rust

Rust

Made by DeepSource

Construction of Iterator from single-element collection RS-W1200

Anti-pattern
Minor
Autofix

Construction of single-element collections, such as arrays or vectors, for the sole purpose of iteration, can be detrimental to performance. Consider using std::iter::once instead.

Bad practice

let mut v = vec![1, 2, 3];

for x in v.chain([4]) {}

Recommended

let mut v = vec![1, 2, 3];

for x in v.chain(std::iter::once(4)) {}