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

Ownership, Move Semantics & Drop

Master Rust's signature feature: every value has one owner, moves prevent double-frees, and memory drops deterministically.

What you'll learn

  • Explain the three rules of Rust ownership
  • Distinguish Copy stack types (i32, bool) from Move heap types (String, Vec)
  • Know when .clone() is appropriate vs borrowing

Overview

Master Rust’s signature feature: every value has one owner, moves prevent double-frees, and memory drops deterministically.

Code Example

fn main() {
    let s1 = String::from("devpath");
    let s2 = s1; // ownership moved to s2
    println!("{s2}"); // s1 can no longer be used here
}

Key Takeaways

  • Explain the three rules of Rust ownership
  • Distinguish Copy stack types (i32, bool) from Move heap types (String, Vec)
  • Know when .clone() is appropriate vs borrowing

Quick Check

Check Your Understanding

Score: 0 / 1

1. Why does Rust invalidate `s1` after `let s2 = s1;` for a heap-allocated `String`?

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