Page 02

Rust

Borrowing Basics

Core idea Rust separates ownership from borrowing so the compiler can prevent data races and dangling references before runtime. Revision points One mutable reference or many immut...

Intermediate17 Apr 2026#rust#ownership#safety

Core idea

Rust separates ownership from borrowing so the compiler can prevent data races and dangling references before runtime.

Revision points

  • One mutable reference or many immutable references.
  • References cannot outlive the value they point to.
  • Borrow checking pushes lifetime decisions earlier in design.
fn print_length(value: &String) {
    println!("{}", value.len());
}

fn main() {
    let name = String::from("notes");
    print_length(&name);
}

What to remember

When a Rust API feels strict, it is usually forcing you to clarify ownership boundaries.