Curriculum Ownership & borrowing Moves and Copy
Moves and Copy
TypeScript variables point at values managed by a garbage collector; Rust bindings own values unless the type is Copy. This theme makes moves concrete before references appear. Planned exercises: 1. choose which binding owns a String. 2. recognise a move. 3. recognise a Copy integer. 4. fill the line that avoids using a moved value. 5. fill a clone() only where an owned duplicate is intended. 6. write a function that takes ownership. 7. write a function that returns ownership. 8. translate TS object passing into Rust moves. 9. fix a use-after-move compiler error.
Exercises
9 ready
01
pick one
In Rust, each value has exactly ONE owning binding at a time.
02
pick one
rustc emits this diagnostic on the program below. Pick the line
03
pick one
Some types implement Copy. For those, assignment COPIES the
04
type one line
The program below moves name into owner, then tries to
05
type one line
The program needs to keep using name AFTER passing a copy
06
write a program
Write a Rust program with a helper consume(s: String) that
07
write a program
Write a Rust program with a helper build_name() -> String
08
write a program
Translate the TypeScript pattern: a function consumes a value,
09
write a program
The following Rust program fails to compile: