How can I concisely define multidimensional `Vec`s in Rust?

Viewed 53

When initializing a multidimensional Vec in Rust, I can use the vec!-macro like this:

vec![vec![0; 100]; 200]

However, this gets messy for Vecs of higher dimensions. Currently, I am using this:

vec![vec![vec![vec![vec![vec![vec![vec![0; N-1]; N-1]; N-1]; N-1]; 2]; 2]; 2]; 2]

This is not very concise, and also the order in which the dimensions are written is reverse to the indexing order. Is there a more concise way to do this? I am looking for something like

vec![0; 2, 2, 2, 2, N-1, N-1, N-1, N-1]
0 Answers
Related