From the course: Rust Essential Training

Unlock the full course today

Join today to access over 24,400 courses taught by industry experts.

Multidimensional arrays

Multidimensional arrays - Rust Tutorial

From the course: Rust Essential Training

Multidimensional arrays

- Arrays in Rust can have more than one dimension. If we think of a basic one-dimensional array as being like a row of parked cars with each spot having a unique index number to identify it, then a two-dimensional array is like a parking lot where you'll need two index values to locate your car. You'll need to know which row you parked on, and then which spot along that row. Taking that analogy even further, a three-dimensional array is like a multi-story parking garage. To find your car, you'll need three index values. Which floor you parked on, which row on that floor, and then which spot along that row. It's hard to imagine a four-dimensional parking garage. So we'll stop the analogy there. We can initialize a two-dimensional array in Rust by nesting several one dimensional arrays within another array. This initializes two arrays with three elements each. The first one contains one, two, three, and the second one…

Contents