enumerate pairs each item with its index, and filter_map can keep only the indexes that match.

Program

Play the program to choose a status value and collect the matching positions.

enumerate_filter_map.rs
fn main() {
    let target = ;
    let statuses = ["open", "closed", "open"];
    let indexes: Vec<usize> = statuses.iter().enumerate().filter_map(|(index, status)| if *status == target { Some(index) } else { None }).collect();
    println!("{:?}", indexes);
}
fn main() {
    let target = ;
    let statuses = ["open", "closed", "open"];
    let indexes: Vec<usize> = statuses.iter().enumerate().filter_map(|(index, status)| if *status == target { Some(index) } else { None }).collect();
    println!("{:?}", indexes);
}
fn main() {
    let target = ;
    let statuses = ["open", "closed", "open"];
    let indexes: Vec<usize> = statuses.iter().enumerate().filter_map(|(index, status)| if *status == target { Some(index) } else { None }).collect();
    println!("{:?}", indexes);
}
enumerate `enumerate` yields `(index, value)` pairs from the input iterator.
filter_map `filter_map` drops `None` and unwraps `Some(index)` in one step.
positions The collected vector stores matching positions rather than matching values.