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.

Applied Intermediate

16  Smart pointers

Box gives a value a fixed-size home on the heap -- which is what makes recursive types possible. Rc adds shared ownership: several owners of one allocation, freed when the last one drops.

Step 2 / 2

In make_duo, give both players the SAME team allocation -- clone the Rc, not the String.

Hints
  • Rc::clone(&team) bumps the reference count -- it never copies the String.
  • Give one player a clone and let the other take team itself.
16_smart_pointers.rs
Reset to starterCompiled in a sandbox; hidden checks must pass.
Reveal solution
use std::rc::Rc;

struct Player { name: &'static str, team: Rc<String> }

fn make_duo(team: Rc<String>) -> (Player, Player) {
    let a = Player { name: "ash", team: Rc::clone(&team) };
    let b = Player { name: "brook", team };
    (a, b)
}