I want to define function that takes one argument which is "special" array, like in example below:
[5, 2, [7, -1], 3, [6, [-13, 8], 4]]
This array is a non-empty array that contains either integers or other "special" arrays.
What should be the proper argument type of the function that receives such "special" array?
You cannot give an array like that as a parameter to a function, because it is ot homogeneous. However, you can define your own type of special array.
The following code shows how to encode a special array [2, [2, 2]]:
You can use pattern matching to check on which kind of enum element you have in the array, either an Integer or a Vector:
To iterate through such an array you need a function that can evaluate reccursively, because the Vector arm has nestef elements. We can define a function that evals reccursively as such:
One thing worth noticing is that since we capture by value, we cause a move, so we can safely use into_iter to make sure we consume all the values.