I am attempting to return a 2D array from a function with this prototype:
fn function1(rep1: usize, rep2: usize) -> (Vec<Vec<bool>>) {
There is this 2D vector struct in the function:
let mut array2d: Vec<Vec<bool>>;
I am using following itertools loop:
for perm in items.iter().permutations(items.len()).unique() {}
Each instance of perm
is Vec<&bool>
rather than Vec<bool>
and so in every loop upon trying to push into array2d
with array2d.push(perm);
I get the following error:
note: expected struct `Vec<bool>` found struct `Vec<&bool>`
Initially I have attempted at modifying the return specifier to allow me to return 2D Vec of pointers but failed somehow at doing so. I'd be grateful if someone could show me how to dereference/cast vector of addresses as a vector of values and/or how to change return specifier so that I can return Vec<Vec<&bool>>
rather than Vec<Vec<bool>>
.
Full code snippet:
fn function1(rep1: usize, rep2: usize) -> (Vec<Vec<bool>>) {
let mut array2d: Vec<Vec<bool>>;
let mut items = vec![false; rep2];
for r in 0..(rep1 - 1){
items[r] = true;
}
for perm in items.iter().permutations(items.len()).unique() {
array2d.push(perm);
}
return array2d;
}