Use position to find position of an element in iterator. Returns None if the element does not exist.
1
2
3
4
5
6
let nums = [1, 2, 3];
let pos = nums.iter().position(|value| *value == 3);
assert_eq!(pos, Some(2));
let pos = nums.iter().position(|value| *value == 10);
assert_eq!(pos, None);