quest

Sign in to start training

quest keeps your progress, streaks, and scores tied to your account — so you can pick up on any device.

Synced everywhere. Progress follows you across laptop and phone.
Streaks & stats. See your daily run and every score over time.
Your profile. A name and avatar for the work you do here.

We only use Google to sign you in and sync progress. No posting, no contacts — ever.

Borrow checker Advanced

28  Interior mutability

Sometimes a value must change behind a shared reference -- a counter, a cache, a shared log. Cell and RefCell move the borrow rules to runtime; Rc<RefCell<..>> is the classic shared-mutable combo.

Step 1 / 2

Fix Tracker so record can count through &self: store the hits in a Cell.

Hints
  • Cell<u32> allows get/set through &self for Copy types.
  • self.hits.set(self.hits.get() + 1); the getter becomes self.hits.get().
28_interior_mut.rs
Reset to starterCompiled in a sandbox; hidden checks must pass.
Reveal solution
use std::cell::Cell;

struct Tracker { hits: Cell<u32> }

impl Tracker {
    fn record(&self) {
        self.hits.set(self.hits.get() + 1);
    }
    fn hits(&self) -> u32 {
        self.hits.get()
    }
}