Hi guys, sorry if this question has already been discussed numerous times, but I failed to find the answer which would make the following clear for me:
There's an example in Rustonomicon Section 3.2. Aliasing:
fn compute(input: &u32, output: &mut u32) {
let mut temp = *output;
if *input > 10 {
temp = 1;
}
if *input > 5 {
temp *= 2;
}
*output = temp;
}
What I already know (please correct me if I'm wrong) doing let b = a;
for primitive types do Copy
. For complex types it does Move
and changes ownership: data is moved from one location in the heap to another and b
becomes the owner of this data.
But does this apply to dereferences? The example above uses primitive type, so it looks like dereferenced value is copied to temp
. But what if I had a reference to some complex data type?
Does dereferencing it actually moves data to temp
so that temp becomes the owner?