Function permutator::copy::cartesian_product
source · [−]Expand description
Create a cartesian product over given slice. The result will be a slice
of T
.
Parameters
sets
A slice of slice(s) containsT
elements.cb
A callback function. It will be called on each product.
Return
A function return a slice of T
element out of parameter sets
.
It return value as parameter of callback function cb
.
Unsafe
This function use unsafe code to create a copy of result. One is use to perform mutation without creating a new result. Another is use to send to callback function. Internally, the result mutation and callback call will be done in sequence so it should be safe.
Examples
To print all cartesian product between [1, 2, 3] and [4, 5, 6].
use permutator::cartesian_product;
cartesian_product(&[&[1, 2, 3], &[4, 5, 6]], |product| {
// First called will receive [1, 4] then [1, 5] then [1, 6]
// then [2, 4] then [2, 5] and so on until [3, 6].
println!("{:?}", product);
});