Slug: borrow-nll-01 · Paired reading: Chapter 6
Prompt
fn last_then_clear(v: &mut Vec<i32>) -> Option<i32> — copy out the
last element, then clear() the vec. NLL ends the last() borrow
before clear needs &mut.
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 30
Slug: borrow-nll-01 · Paired reading: Chapter 6
fn last_then_clear(v: &mut Vec<i32>) -> Option<i32> — copy out the
last element, then clear() the vec. NLL ends the last() borrow
before clear needs &mut.