Step Into Rust · Lesson 3 · Ownership & Types
Ownership & Borrowing
Moves, clones, shared and mutable references, String vs &str.
- ~35 minreading and coding
- 4missions
- membersaccess
- Rustlanguage
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
- The rule that replaces free()
- Moves
- Borrowing
- String vs &str
Missions
- Borrow, don't take
- A mutable borrow
- Clone on purpose
- Return a slice