To create a three-dimensional vector in Rust, you can use nested vectors.
In this example,
fn main() {
// Step 1: Create a numeric three-dimensional vector
let mut three_dimensional_vector: Vec<Vec<Vec<i32>>> = vec![
vec![vec![1, 2, 3], vec![4, 5, 6], vec![7, 8, 9]],
vec![vec![10, 11, 12], vec![13, 14, 15], vec![16, 17, 18]],
vec![vec![19, 20, 21], vec![22, 23, 24], vec![25, 26, 27]],
];
// Step 2: Print the vector
println!("{:?}", three_dimensional_vector);
}
[[[1, 2, 3], [4, 5, 6], [7, 8, 9]], [[10, 11, 12], [13, 14, 15], [16, 17, 18]], [[19, 20, 21], [22, 23, 24], [25, 26, 27]]]
In this example,
fn main() {
// Step 1: Create a string three-dimensional vector
let mut three_dimensional_vector: Vec<Vec<Vec<&str>>> = vec![
vec![vec!["a", "b", "c"], vec!["d", "e", "f"], vec!["g", "h", "i"]],
vec![vec!["j", "k", "l"], vec!["m", "n", "o"], vec!["p", "q", "r"]],
vec![vec!["s", "t", "u"], vec!["v", "w", "x"], vec!["y", "z", "!"]],
];
// Step 2: Print the vector
println!("{:?}", three_dimensional_vector);
}
[[["a", "b", "c"], ["d", "e", "f"], ["g", "h", "i"]], [["j", "k", "l"], ["m", "n", "o"], ["p", "q", "r"]], [["s", "t", "u"], ["v", "w", "x"], ["y", "z", "!"]]]
In this tutorial, we learned How to create a Three Dimensional Vector in Rust language with well detailed examples.