I would like to sum elements in a vector whose index exists in a hashset.
I assume there is a combination of iterator adaptors I could use to achieve this, but can't seem to figure out what to use. I know I could create a function and use a for loop over the vector, but I want to do the calculation inline and store straight into a variable.
An example of the behaviour I would like:
use std::collections::HashSet;
let v: Vec<u32> = vec![5, 3, 7, 4, 3, 2, 1];
let s: HashSet<u32> = [2, 3, 6].iter().copied().collect();
let actual = v.iter()....
let expected = 12;
assert_eq!(actual, expected);