I'm trying to get the intersection of multiple sets of strings, and I'm wondering if there's a more elegant way than what I'm using so far:
let binaries: Vec<HashSet<String>> = ... let common_binaries: HashSet<&str> = binaries .iter() .filter(|b| binaries[1..].iter().all(|set| set.contains(*b))) .map(|b| &b[..]) .collect();
I'm computing the intersection manually via "all" and "contains" because there doesn't seem to be an intersection function that takes multiple sets (https://github.com/rust-lang/rfcs/issues/2023). However, the explicit accesses to the first and the remaining elements of the vector don't seem very elegant...
Then I'm not sure about String vs str: the String instances in "binaries" outlive the intersection, so I'd like to use references to avoid copying the strings. I guess an alternative to the above would be to use "&String" instead of "&str", which would allow me to drop the call to "map" - would that be idiomatic?
Thanks for your help!