typeover
rust curriculum

Curriculum Production Rust Interior mutability exercise 3 · mcq

Interior mutability

A struct holds a single u32 counter that needs to update through &self. The value is Copy and never needs to be borrowed by reference. Pick the cheapest wrapper.

TypeScript reference
Pick the idiomatic Go translation

About this theme

Sometimes Rust permits mutation through a shared reference by moving borrow checks to runtime. This theme teaches Cell, RefCell, and the Rc<RefCell<T>> pattern as tools with costs, not escape hatches. Planned exercises: 1. choose RefCell for runtime-checked mutation. 2. recognise borrow_mut. 3. choose Cell for small copy values. 4. fill RefCell::new. 5. fill a scoped mutable borrow. 6. write a counter using Cell. 7. write a shared mutable graph edge with Rc<RefCell<_>>. 8. translate TS shared mutation deliberately. 9. fix a runtime borrow panic by shortening a borrow.