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 22

Mutable borrow ends before the next use

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

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

Prompt

fn push_then_first(v: &mut Vec<i32>, x: i32) -> Option<i32> — push x, then return the first element by value (copied). Structure so the exclusive borrow for push ends before first().