singularity

Ownership

rebel types / copy trait

⚠️ To see why, consider what would happen if a type like Box were Copy. If we executed box2 = box1, then box1 and box2 would both believe that they owned the heap memory allocated for the box, and they would both attempt to free it when they went out of scope. Freeing the memory twice could have catastrophic consequences.

let x1 = 42;
let y1 = Box::new(84);
{ // starts a new scope
  let z = (x1, y1);
  // z goes out of scope, and is dropped;
  // it in turn drops the values from x1 and y1
}

// x1's value is Copy, so it was not moved into z
let x2 = x1;
// ❌ y1's value is not Copy, so it was moved into z
//let y2 = y1;

Listing 1-3