Skip to content

Lesson 02 · Backend & Systems with Rust

Rust: Ownership & Borrowing

The heart of Rust: every value has exactly one owner, assignment moves it, references borrow it under two compile-time rules, and String and &str are two different tools for text.

Prerequisites: Rust: Fundamentals with Cargo

Learning objectives
By the end of this lesson, you will be able to:
  • Apply the ownership rules: one owner per value, dropped when its owner's scope ends
  • Predict whether an assignment copies or moves a value, and repair use-after-move errors with clone or a reference
  • Borrow with & and &mut under the two compile-time borrow rules, resolving E0502 conflicts
  • Slice strings and sequences with &str and &[T] without copying
  • Choose &str over String in function signatures and justify the choice