Two dimensional vectors in Rust

爷,独闯天下 提交于 2019-11-29 14:17:34

You could use the macro vec! to create 2d vectors.

fn test(vec: &mut Vec<Vec<char>>){
    vec[0][0] = 'd';
    ..//
    vec[23][79] = 'd';
}

fn main() {

    let mut vec = vec![vec!['#'; 80]; 24];

    test(&mut vec);
}
Niko Matsakis

Did you intend that all of the subarrays will have the length 2, as in this example? In that case, the type of the parameter should not be &[u8], which is a borrowed array of u8's, but rather &[[u8; 2]].

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!