use std::collections::*; use std::hash::Hash; use std::iter::FromIterator; trait SetFunc { type Set: IntoIterator + FromIterator; } struct BTreeSetF; impl SetFunc for BTreeSetF { type Set = BTreeSet; } struct HashSetF; impl SetFunc for HashSetF { type Set = HashSet; } fn uni + SetFunc<(T,T)>, T: Copy>(input: &[T]) -> usize { input.iter().copied().collect:: < >::Set > ().into_iter().count() * input.windows(2).map(|a|(a[0], a[1])).collect:: < >::Set > ().into_iter().count() } fn main() { println!("{}", uni::(&[1,2,3,3,2,3])); println!("{}", uni::(&[1,2,3,3,2,3])); }