Ownership in Practice · 14 min · free with an account

Mutable Borrows

Lesson preview · about 30%

One temporary writer with exclusive access.

Core idea

An &mut reference permits mutation without transferring ownership.

Start with the idea

An &mut reference permits mutation without transferring ownership. Exclusivity lasts through its final use, preventing another reader or writer from observing a half-finished update.

An &mut T gives one caller exclusive temporary access to a value. The owner still exists, but it cannot read or write through another path while the mutable borrow is active. This is more than a rule about syntax: it prevents a reader from seeing a partially updated structure and prevents two writers from racing to change the same state. After the last use of the borrow, the owner can be used again.

In add_one, the star in *value += 1 follows the mutable reference to the integer it points at.

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.

← All lessons in Ownership Mastery