Why does mut inside a struct dereference trigger a copy? In the example below what are the semantics behind the additional mut included in the last function?
struct Wrapper {
data: [u32; 1],
}
fn main() {
let mut wrapper = Wrapper { data: [1] };
println!("Initial value: {:?}", wrapper.data); // Initial value: [1]
modify_wrapper(&mut wrapper);
println!("Value after non-mut fn: {:?}", wrapper.data); // Value after non-mut fn: [2]
modify_wrapper_mut(&mut wrapper);
println!("Value after mut fn: {:?}", wrapper.data); // Value after mut fn: [2]
}
fn modify_wrapper(Wrapper { data }: &mut Wrapper) {
data[0] += 1;
}
fn modify_wrapper_mut(Wrapper { mut data }: &mut Wrapper) {
data[0] += 1;
}
Thanks! Annoying that the linting suggestions in the other thread haven't got to the top of the list to implement yet. Glad to see I'm not being totally thick.