Function intersection::hash_set::intersection
source · pub fn intersection<I, Set, T>(sets: I) -> HashSet<T>where
I: IntoIterator<Item = Set>,
Set: IntoIterator<Item = T>,
T: Clone + Eq + Hash,
Expand description
Takes the intersection between the given Set
iterables, with common type T
.
Example
use std::collections::HashSet;
use intersection::hash_set;
let tokens = "hello,world,common";
let sets = tokens.split(',') // split to words, each word is a set.
.map(|word| word.chars()); // split word to chars, each char is an element of the set.
// we look for the common letters between the 3 words
let common_letters = hash_set::intersection(sets);
let expected = HashSet::from(['o']);
assert_eq!(common_letters, expected);