Trait const_combinations::SliceExt [−][src]
pub trait SliceExt<T> {
fn combinations<const K: usize>(&self) -> SliceCombinations<'_, T, K>ⓘNotable traits for SliceCombinations<'a, T, K>impl<'a, T, const K: usize> Iterator for SliceCombinations<'a, T, K> type Item = [&'a T; K];;
fn permutations<const K: usize>(&self) -> SlicePermutations<'_, T, K>ⓘNotable traits for SlicePermutations<'a, T, K>impl<'a, T, const K: usize> Iterator for SlicePermutations<'a, T, K> type Item = [&'a T; K];;
}Required methods
fn combinations<const K: usize>(&self) -> SliceCombinations<'_, T, K>ⓘNotable traits for SliceCombinations<'a, T, K>impl<'a, T, const K: usize> Iterator for SliceCombinations<'a, T, K> type Item = [&'a T; K];
fn combinations<const K: usize>(&self) -> SliceCombinations<'_, T, K>ⓘNotable traits for SliceCombinations<'a, T, K>impl<'a, T, const K: usize> Iterator for SliceCombinations<'a, T, K> type Item = [&'a T; K];
Notable traits for SliceCombinations<'a, T, K>
impl<'a, T, const K: usize> Iterator for SliceCombinations<'a, T, K> type Item = [&'a T; K];Return an iterator that iterates over the k-length combinations of the elements from a slice.
The iterator produces a new array per iteration, and returns references to the
elements of the slice. If K is greater than the length of the input slice the
resulting iterator will yield no items.
Examples
use const_combinations::SliceExt; let mut combinations = [1, 2, 3, 4].combinations(); assert_eq!(combinations.next(), Some([&1, &2, &3])); assert_eq!(combinations.next(), Some([&1, &2, &4])); assert_eq!(combinations.next(), Some([&1, &3, &4])); assert_eq!(combinations.next(), Some([&2, &3, &4])); assert_eq!(combinations.next(), None);
Note: Combinations does not take into account the equality of the slice elements.
let mut combinations = [1, 2, 2].combinations(); assert_eq!(combinations.next(), Some([&1, &2])); // Note: these are the same assert_eq!(combinations.next(), Some([&1, &2])); // Note: these are the same assert_eq!(combinations.next(), Some([&2, &2])); assert_eq!(combinations.next(), None);
fn permutations<const K: usize>(&self) -> SlicePermutations<'_, T, K>ⓘNotable traits for SlicePermutations<'a, T, K>impl<'a, T, const K: usize> Iterator for SlicePermutations<'a, T, K> type Item = [&'a T; K];
fn permutations<const K: usize>(&self) -> SlicePermutations<'_, T, K>ⓘNotable traits for SlicePermutations<'a, T, K>impl<'a, T, const K: usize> Iterator for SlicePermutations<'a, T, K> type Item = [&'a T; K];
Notable traits for SlicePermutations<'a, T, K>
impl<'a, T, const K: usize> Iterator for SlicePermutations<'a, T, K> type Item = [&'a T; K];Return an iterator that iterates over the k-length permutations of the elements from a slice.
The iterator produces a new array per iteration, and clones the iterator
elements. If K is greater than the length of the input slice the
resulting iterator adaptor will yield no items.
Examples
let mut permutations = [0, 1, 2].permutations(); assert_eq!(permutations.next(), Some([&0, &1])); assert_eq!(permutations.next(), Some([&1, &0])); assert_eq!(permutations.next(), Some([&0, &2])); assert_eq!(permutations.next(), Some([&2, &0])); assert_eq!(permutations.next(), Some([&1, &2])); assert_eq!(permutations.next(), Some([&2, &1])); assert_eq!(permutations.next(), None);
Note: Permutations does not take into account the equality of the slice elements.
let mut permutations = [2, 2].permutations(); assert_eq!(permutations.next(), Some([&2, &2])); // Note: these are the same assert_eq!(permutations.next(), Some([&2, &2])); // Note: these are the same assert_eq!(permutations.next(), None);