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 6

Partial moves from a struct

own-move-04Related book chapters: 5 (optional — this page is complete on its own)ownershippartial-move

Slug: own-move-04 · Paired reading: Chapter 5

Prompt

Given struct Pair { a: String, b: String }, implement fn take_a(p: Pair) -> (String, Pair) that returns field a and a Pair whose a is empty and whose b is the original b.

Rust angle

Partial moves leave the rest of the struct uninitialized for moved fields — rebuild explicitly.