Introduction to Rust - Part 12: Boxing and Trait Objects

Опубликовано: 17 Март 2026
на канале: Rhymu's Videos
1,755
85

This is the 12th in a series of videos that cover, step by step, learning to code using the Rust programming language.

In this video we'll introduce Boxing and Trait Objects, after covering some basics about different kinds of ways in which values are stored in memory.

0:00 - Introduction
0:24 - Values on the Stack
1:06 - Constants
1:39 - Global Variables
3:57 - Heap Variables
5:27 - Using Box to put values on the Heap
7:36 - Direct heap memory allocation: "alloc", "Layout", and "Box::from_raw"
9:16 - Review of constants, globals, stack, and heap variables
9:42 - Using Box for indirection in complex types
13:53 - Just for fun: recursive function navigating our complex type
15:02 - Introducing Trait Objects
18:43 - Trait Objects and Type Erasure
19:33 - Using Boxed Trait Objects to represent different errors
20:22 - In Summary