Curriculum Ownership & borrowing Mutable borrowing
Mutable borrowing
The borrow checker's headline rule is simple but unfamiliar: many shared borrows or one mutable borrow, never both at the same time. This theme teaches &mut T, reborrowing, and scope as the tool for ending borrows. Planned exercises: 1. choose &mut for an updater. 2. recognise the one-mutable-borrow rule. 3. choose a smaller scope. 4. fill a mutable parameter. 5. fill a mutable call site. 6. write an in-place updater. 7. write code that reads after a mutable borrow ends. 8. translate TS mutation into Rust borrowing. 9. fix overlapping borrow diagnostics.
Exercises
9 ready
01
pick one
A function appends an exclamation mark to a String in place. Pick
02
pick one
rustc rejects the program below with `error[E0499]: cannot borrow
03
pick one
When does a mutable borrow END, releasing the value so the owner
04
fill blanks
Fill the qualifier that turns this String parameter into a
05
fill blanks
Fill the qualifier at the CALL SITE that hands s to a function
06
type one line
Write the function signature for append_bang. It takes a
07
write a program
Write a Rust program that:
08
write a program
Translate the TypeScript array-mutator into Rust. double_all
09
write a program
The program below fails with error[E0499]: cannot borrow s` as