I'm in the process of learning Rust
, but I could not find an answer to this question.
In PHP, there's the array_column
method and it works this way:
given an array of arrays (this would be a a Vector of vectors in Rust):
$records = [
[1,2,3],
[1,2,3],
[1,2,3],
[1,2,3]
];
if I want to get an array containing all the first elements (a "column") of the inner arrays I can do:
$column = array_column($records, 0);
This way, for example, I get [1,1,1,1]
. If I change that 0 with 1, I get [2,2,2,2]
and so on.
Since there's no array_column
equivalent in Rust (that is: I could not find it), what could be the best way to implement a similar behavior with a vector of vectors?