FFORGE//RS
← Roadmap

rust / LEVEL 2

The reference that disappeared

EST.25 MIN
01

THEORY / RETRIEVAL

What to restore

  • Distinguish moving a mutable reference from reborrowing it
  • Use iter_mut without cloning the collection

Mutable references are not Copy

An `&mut T` represents exclusive access. Passing that reference by value can move the reference binding even though the underlying value remains borrowed. This is why a later use of the same binding may fail with E0382.

Reborrow for the shortest useful lifetime

Methods such as `iter_mut()` create a fresh, shorter mutable reborrow. The iterator owns that temporary reborrow; after the loop, the original `&mut Vec<T>` binding can be used again.

CHECKPOINT

A function loops over `accounts: &mut Vec<i64>` and then calls `accounts.push(100)`. Which loop preserves the ability to call `push` without cloning?

ISOLATED RUST 1.96
src/lib.rsEDIT

02 / DEBUGGING

Find and fix the defect

Fix `normalize` so it clamps negative balances and appends the reserve account. Do not clone the vector and keep the function signature unchanged.

Initializing editor…
CLOUD SANDBOXnetwork off · 256 MB · 12 s
1 / 64 KB
OUTPUT
Runner is waiting for a submission.