Overview
Save Big on Coursera Plus. 7,000+ courses at $160 off. Limited Time Only!
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