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 27

Two mutable slices with split_at_mut

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

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

Prompt

Implement fn swap_halves(a: &mut [i32]) that swaps a[0] with a[mid] where mid = a.len()/2, for len >= 2. Use split_at_mut — do not index twice with simultaneous &mut from the same slice.