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 26

Push while a reference is live

borrow-excl-01Related book chapters: 6 (optional — this page is complete on its own)E0502aliasing

Slug: borrow-excl-01 · Paired reading: Chapter 6

Prompt

Implement fn first_then_push(v: &mut Vec<i32>, x: i32) -> Option<i32> that returns a copy of the first element (if any), then pushes x. The point is to structure borrows so this compiles — you may not hold a reference across the push.