Class Central is learner-supported. When you buy through links on our site, we may earn an affiliate commission.

YouTube

Introduction to Structs, Traits, and Zero-Cost Abstractions in Rust

Rust via YouTube

Overview

Explore an introduction to structs, traits, and zero-cost abstractions in Rust through this 22-minute conference talk recorded at the Rust KW Meetup in Kitchener-Waterloo, Canada. Gain insights into building efficient abstractions and writing better code without compromising performance. Learn about structs, traits, generics, and their applications in Rust programming. Discover the concept of zero-cost abstractions and their benefits. Examine practical examples, including append-only vectors and logger implementations. Compare dynamic dispatch with trait objects to generics, and understand their impact on optimization. Ideal for programmers experienced in other languages but new to Rust.

Syllabus

Intro
Why Rust? (for me)
Introducing: structs
Add some methods
Using Point2D
Let's add a parameter
Thinking like a compiler
Zero cost abstraction!
What can we do with zero cost abstractions?
Append-only vectors
The recipe
A motivating example
How about a "Logger" type?
Different types of Loggers
Better idea: a Logger trait
PrintLogger implements Logger
Pass me a Logger, any Logger
Dynamic dispatch with trait objects
Trait objects prevent some optimizations
Generics!
Add logging to a fibonacci calculation
Generics vs trait objects

Taught by

Rust

Reviews

Start your review of Introduction to Structs, Traits, and Zero-Cost Abstractions in Rust

Never Stop Learning.

Get personalized course recommendations, track subjects and courses with reminders, and more.

Someone learning on their laptop while sitting on the floor.