I'm trying to implement Heap's algorithm in rust and am struggling to do so. I'm essentially trying to port the example from this blog.

```
fn swap(mut v: Vec<usize>, i: usize, j: usize) -> Vec<usize> {
let t = v[i];
v[i] = v[j];
v[j] = t;
v
}
fn heaps_alg(mut v: Vec<usize>, n: usize) -> Option<Vec<usize>> {
if n == 1 {
println!("Permution complete: {:?}", v);
Some(v.clone());
}
for i in 0..n {
heaps_alg(v.clone(), n-1);
let j = {if n % 2 == 0 { i } else { 0 } };
if n - 1 == j { continue } else {
v = swap(v.clone(), n-1, j);
}
}
None
}
fn main() {
heaps_alg(vec![1,2,3], 3);
}
```

Output:

```
Permution complete: [1, 2, 3]
Permution complete: [2, 1, 3]
Permution complete: [3, 2, 1]
Permution complete: [2, 3, 1]
Permution complete: [1, 2, 3]
Permution complete: [2, 1, 3]
```

As you can see, the number of permutations is correct, but there are duplicates leading to an incomplete collection of permutations. It seems my algorithm is not performing the swap correctly. Any suggestions or help in troubleshooting?