Function intersection::btree_set::intersection
source · pub fn intersection<I, Set, T>(sets: I) -> BTreeSet<T>where
I: IntoIterator<Item = Set>,
Set: IntoIterator<Item = T>,
T: Clone + Ord,
Expand description
Takes the intersection between the given Set
iterables, with common type T
.
Example
use std::collections::BTreeSet;
use intersection::{btree_set};
let tokens = "harry,hairy,happy";
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 = btree_set::intersection(sets);
let expected = BTreeSet::from(['h', 'a', 'y']);
assert_eq!(common_letters, expected);