Question about dereferencing and ownership

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?

Hi, you can try it playground. Since String isn't Copy the compiler will try to move it but can't since you only have a reference.

Ah, I read books and make notes, but always forget about the playground... Thanks a lot!

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.