Curriculum Production Rust Smart pointers
Smart pointers
Smart pointers encode ownership strategies in types. This theme covers Box<T> for heap allocation and recursive types, Rc<T> for shared single-thread ownership, and Arc<T> for shared thread-safe ownership. Planned exercises: 1. choose Box for recursive data. 2. recognise shared ownership with Rc. 3. choose Arc across threads. 4. fill Box::new. 5. fill Rc::clone. 6. write a boxed enum node. 7. write shared ownership without cloning the inner value. 8. translate TS shared object references. 9. fix a type whose size would otherwise be infinite.
Exercises
9 ready
01
pick one
A recursive enum (each node may carry a child of the SAME
02
pick one
Two structures in a SINGLE-THREADED program both need to OWN
03
pick one
A value needs to be SHARED by ownership ACROSS THREADS. Pick
04
fill blanks
Fill the associated function that allocates a value on the
05
fill blanks
Fill the IDIOMATIC associated-function form that bumps the
06
write a program
Define a recursive enum List with two variants:
07
write a program
Use Rc to SHARE a String between two bindings without
08
write a program
Translate the TS pattern that shares one object reference
09
write a program
This program fails with error[E0072]: recursive type List`