Enter your book access code

The curriculum, drills, tutor, and interviewer mode are for readers of Ace the Rust Interview. The code is printed in the Preface (Companion site access).

Don’t have the book yet? The landing page stays open — purchase unlocks this gym.

intermediate · order 53

Replace Rc<RefCell> with indices

unsafe-redesign-03Related book chapters: 4 (optional — this page is complete on its own)Rc-RefCellsmell

Slug: unsafe-redesign-03 · Paired reading: Chapter 4

Prompt

Tiny arena tree: struct Tree { nodes: Vec<Node> } with Node { val, left: Option<usize>, right: Option<usize> }. Implement fn insert_left(&mut self, parent: usize, val: i32) -> usize and fn get(&self, idx: usize) -> Option<i32>.