This crate give you all the combinations of values in a vec
let actual: Vec<_> = Combinations::new(vec![1, 2, 2, 3, 4], 3).collect();
let expected = vec![
vec![1, 2, 2],
vec![1, 2, 3],
vec![1, 2, 4],
vec![1, 3, 4],
vec![2, 2, 3],
vec![2, 2, 4],
vec![2, 3, 4],
];
assert!(actual == expected);
Any contributions are welcomed.