Start with the idea
Passing &mut *value creates a shorter reborrow instead of moving the original mutable reference. This lets a helper work briefly and returns control to the outer borrower afterward.
A mutable reference can temporarily lend its access to another function. In twice, each bump(&mut *value) creates a shorter reborrow from the outer &mut i32. The first helper finishes before the second begins. The original reference is not consumed, so it can be used again after the helper calls. The important property is the timeline: there is one active writer at a time.
The * dereferences the outer reference to the value, and &mut forms a new mutable borrow of it.
Keep learning, for free
The rest of this lesson is waiting for you.
Create a free account to read the complete explanation, see the infographic, explore the code, and try the exercises. All 742 lessons and algorithm steps are included.
No payment details. Your account opens the complete Academy.