Hey there,
I've been trying to implement Heap's algorithm, however every example I found so far would create an array with every permutation. This is my attempt to create a "lazy" version of it, an iterator the figures out the next iteration as you call next() and doesn't create a potentially huge vec to store the permutations.
There was a Bug at the end that would break permutations with a length greater than 4:
if depth > 2 {
//if depth == value.len() {
// self.stack
// .extend((2..value.len()).rev().map(|index| (index, 0)));
//} else {
// self.stack.push((depth - 1, 0));
//}
// Fixing a bug for it to generate stacks properly when len is
// greater than 4
self.stack
.extend((2..depth).rev().map(|index| (index, 0)));
}