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?
records's size, then iterate each element in outer vector, and add in your result asubvector[k]element. You should also check if everysubvectorhas size greater than klet zipped: Vec<_> = a.iter().zip(b.iter()).collect();(this only works with 2 vectors and it's not enough for me). I don't know what PHP does at a low level, but the implementation of array_column is really fast