我已经构造数组的数组这样的:传递数组函数:阵列必须具有“尺寸”型
let mut my_array = [[false; WIDTH]; HEIGHT];
其中WIDTH
和HEIGHT
预先定义的常量。
我想将整个数组传递给一个函数,并更改数组中的值,但不是数组的大小/长度。
我已经试过:
array_func(&my_array); // (in main function)
fn array_func(arr: &mut [[bool]]) {
println!("{:?}", arr);
}
而我得到的错误:
the trait 'std::marker::Sized' is not implemented for '[bool]'
note: `[bool]` does not have a constant size known at compile-time
note: slice and array elements must have `Sized` type
我的数组的大小应该在编译时知道 - 我不能改变的大小阵列。至少,我认为let mut my_array
意味着我可以更改数组中的值,但不是数组的大小。