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.

beginner · order 23

A guard's drop is the unlock

own-fn-05Related book chapters: 5 (optional — this page is complete on its own)RAIIguard

Slug: own-fn-05 · Paired reading: Chapter 5

Prompt

Implement Lock with lock(&self) -> Guard<'_> that sets an interior Cell<bool> flag, and Guard that clears it on Drop. fn with_lock takes the lock, runs a closure, and relies on drop for release — no manual unlock call.