'Get all the indexes that fulfill a condition in a vector

I would like to know if it is possible to get all the indexes that fulfill a condition in a rust vector datatype. I know the trait operator provides a method to find the first element that does it:

let test=vec![1,0,0,1,1];
let index = test.iter().position(|&r| r == 1);
println!("{}",index) //0

However, I would be interested in obtaining all the indexes that are equal to 1 in the test vec.

let test=vec![1,0,0,1,1];
let indexes =  //Some Code
println!("{:?}",indexes) //0,3,4

What should I do?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source