RS.CLIPPY.MANUAL_FIND

Manual implementation of `Iterator::find`

This checker is a Clippy lint created by The Rust Project Contributors. The documentation shown here is a copy of the original documentation for: manual_find. Copyright ©2025 The Rust Team. All rights reserved.

What it does

Checks for manual implementations of Iterator::find

Why is this bad?

It doesn't affect performance, but using find is shorter and easier to read.

Example

fn example(arr: Vec<i32>) -> Option<i32> {
    for el in arr {
        if el == 1 {
            return Some(el);
        }
    }
    None
}

Use instead:

fn example(arr: Vec<i32>) -> Option<i32> {
    arr.into_iter().find(|&el| el == 1)
}