Value and reference semantics

Structs and tuples are values, so binding, assignment, arguments, and collection insertion all copy them. Arrays and dictionaries are references, so another binding observes mutation of the same collection.

Pointers copy target identity. Closures share captured bindings by reference. None of these rules involve hidden copy-on-write behavior.

struct Box { value: int }

fn main() {
  let original = Box { value: 1 }
  let mut copy = original
  copy.value = 9
  println(original.value)
  let items = [1]
  let alias = items
  alias.push(2)
  println(items.len())
}
Output & diagnostics
Expected:
1
2
Ctrl/⌘+Enter runs the current lesson.