我刚接触Rust,对“引用”和“所有权”的概念感到困惑。我想简单地重新分配一个数组,但是出现了错误。我尝试了以下方法:
fn change(a: &mut [i64; 3]) {
a = [5, 4, 1];
}
但是我遇到了以下错误:
--> main.rs:6:7
|
6 | a = [5, 4, 1];
| ^^^^^^^^^
| |
| expected mutable reference, found array of 3 elements
| help: consider mutably borrowing here: `&mut [5, 4, 1]`
|
= note: expected type `&mut [i64; 3]`
我尝试将&mut
添加到数组中,但是出现了一个全新的错误。有人能指导我正确的方向吗?