When trying to print out the contents of a multidimensional vector in Rust, it seems as though you cannot use the type Vec<Vec<str>>
for the vector.
fn print_multidimensional_array(multi: &Vec<Vec<str>>) {
for y in 0..multi.len() {
for x in 0..multi[y].len() {
print!("{} ", multi[y][x]);
}
println!("");
}
}
With this code, I get the output:
error[E0277]: the trait bound `str: std::marker::Sized` is not satisfied
--> src/main.rs:1:1
|
1 | / fn print_multidimensional_array(multi: &Vec<Vec<str>>) {
2 | | for y in 0..multi.len() {
3 | | for x in 0..multi[y].len() {
4 | | print!("{} ", multi[y][x]);
... |
7 | | }
8 | | }
| |_^ `str` does not have a constant size known at compile-time
|
= help: the trait `std::marker::Sized` is not implemented for `str`
= note: required by `std::vec::Vec`
What type of vector could I use for this to work?
Use
Vec<Vec<&str>>
.See also:
Because I like to make things overly generic...