我已經構造數組的數組這樣的:傳遞數組函數:陣列必須具有「尺寸」型
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
意味着我可以更改數組中的值,但不是數組的大小。