【发布时间】:2023-03-22 21:47:01
【问题描述】:
在下面的代码中,MyStruct { s: 5u32 } 的所有权被let y = x; 移动到了y,但是为什么x.s = 6 仍然有效?
struct MyStruct {
s: u32,
}
fn main() {
let mut x = MyStruct { s: 5u32 };
let y = x;
x.s = 6; //why this line does not cause an error?
println!("{}", y.s);
}
【问题讨论】:
标签: rust