How to use Iterator position and find

Use position to get the index and find to get the value of the first item matching a condition in a Rust iterator.

Use the position method to find the index of the first element matching a condition, or find to get the element itself.

let numbers = vec![1, 2, 3, 4, 5];
let index = numbers.iter().position(|&x| x > 3);
let value = numbers.iter().find(|&&x| x > 3);

position returns Option<usize> (the index), while find returns Option<&T> (a reference to the value).