Step Into Labs

Step Into Rust · Lesson 3 · Ownership & Types

Ownership & Borrowing

Moves, clones, shared and mutable references, String vs &str.

Part of Step Into Rust. The full lesson, its missions and the real compiler and debugger are in the course. Try a free lesson first to see how it works.

In C you decide when to free memory, and the bugs come from getting it wrong. In Rust every value has exactly one owner. When the owner goes out of scope, the value is freed automatically. The compiler tracks ownership at compile time, so there is no runtime cost.

In this lesson

Missions

  1. Borrow, don't take
  2. A mutable borrow
  3. Clone on purpose
  4. Return a slice