Skip to content
Guest
Rust · Course Syllabus Show lessons
Ownership & Borrowing · 10 min read · Intermediate

Borrowing, References & The Borrow Checker

Pass data without transferring ownership using shared (&T) and exclusive mutable (&mut T) references.

What you'll learn

  • Share read-only access with multiple &T references
  • Mutate safely with a single exclusive &mut T reference
  • Understand how the borrow checker prevents data races at compile time

Overview

Pass data without transferring ownership using shared (&T) and exclusive mutable (&mut T) references.

Code Example

fn append_tag(s: &mut String) {
    s.push_str(" [verified]");
}

fn main() {
    let mut title = String::from("Rust");
    append_tag(&mut title);
    println!("{title}");
}

Key Takeaways

  • Share read-only access with multiple &T references
  • Mutate safely with a single exclusive &mut T reference
  • Understand how the borrow checker prevents data races at compile time

Quick Check

Check Your Understanding

Score: 0 / 1

1. Which borrowing combination is FORBIDDEN by Rust's borrow checker in the same active scope?

Study Workspace

Finished this lesson?

Your progress is saved locally in your browser, no account needed.

Search courses, lessons, and references

Type to search across all courses, lessons, and quick references.

Press Esc to close Powered by Pagefind