Hello,
for some unit tests, I need to create deeply nested vectors of usize
, for instance Vec<Vec<Vec<Vec<Vec<usize>>>>>
.
The vectors also need to contain values, which are hard-coded. The easiest way for me for inputting the values is in the form of arrays, because I can copy-paste the arrays from some other source. For instance:
let boundary_array = [
[[
[[0, 3, 2, 1]],
[[4, 5, 6, 7]],
[[0, 1, 5, 4]],
[[1, 2, 6, 5]],
[[2, 3, 7, 6]],
[[3, 0, 4, 7]],
]],
[[
[[8, 11, 10, 9]],
[[12, 13, 14, 15]],
[[8, 9, 13, 12]],
[[9, 10, 14, 13]],
[[10, 11, 15, 14]],
[[11, 8, 12, 15]],
]],
];
However, I actually need a nested vector instead of the array.
The only way I could find to create the desired vectors from an expression is to cast each and every array .to_vec
in the expression itself. For instance:
let boundary_vec: Vec<Vec<Vec<Vec<Vec<usize>>>>> =
[[[[[0, 3, 2, 1].to_vec()].to_vec()].to_vec()].to_vec()].to_vec();
But as you can see, this is very tedious and ugly.
Is there a better way?