Step Into Rust · Lesson 3 · Ownership & Types
Where Your Data Lives
The stack, the heap, how big every type really is, and what a String looks like in memory. The picture that makes ownership obvious.
- ~30 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.
Every value your program uses sits somewhere in memory, an enormous array of bytes. A byte's index is its address, and a reference or pointer is simply an address. Rust gives you precise control over where values live and how big they are. Once you can picture that, ownership and borrowing stop feeling like arbitrary rules.
In this lesson
- Memory is a row of numbered bytes
- Two places to put things
- How big is a value?
- A String is three numbers on the stack
- Moving copies 24 bytes, not the text
- Box: a value on the heap
- Option costs nothing for references
Missions
- Measure the types
- Room to grow
- A move does not copy the text
- Big value, small handle