RS.CLIPPY.ITER_NTH
Using `.iter().nth()` on a standard library type with O(1) element access
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_nth. Copyright ©2025 The Rust Team. All rights reserved.
What it does
Checks for usage of .iter().nth()/.iter_mut().nth() on standard library types that have
equivalent .get()/.get_mut() methods.
Why is this bad?
.get() and .get_mut() are equivalent but more concise.
Example
let some_vec = vec![0, 1, 2, 3];
let bad_vec = some_vec.iter().nth(3);
let bad_slice = &some_vec[..].iter().nth(3);
The correct use would be:
let some_vec = vec![0, 1, 2, 3];
let bad_vec = some_vec.get(3);
let bad_slice = &some_vec[..].get(3);