Uploaded February 2026 | Updated November 2026, 13 hours ago
In this tutorial, we cover generics and traits in Rust. Generics allow you to write functions, structs, and enums that work with multiple types without code duplication (similar to templates in C++ but with zero runtime overhead through monomorphization). Traits define shared behavior across different types, acting like interfaces in other languages to create contracts that guarantee specific functionality.
The written guide for this episode can be found here: digikey.com/en/maker/tutorials/2026/intro-to-embedded-rust-part-6-generics-and-traits
The GitHub repository containing the Docker image and example code for this series can be found here: github.com/ShawnHymel/introduction-to-embedded-rust
This guide walks through five key examples demonstrating generics and traits in action. We start with generic functions, showing how a single swap ‹T, U › () function can work with any tuple types instead of writing separate functions for each combination. You'll learn about trait definitions and implementations, creating a Hello trait and implementing it for a Person struct to demonstrate polymorphic behavior.
We also cover trait bounds in detail, explaining how to constrain generic types to only those implementing specific traits. We explore generic structs with the Pair ‹T, U › example, showing how to create data structures that work with any types while maintaining compile-time type safety, and demonstrate generic enums by building a simplified version of Rust's Option ‹T › type.
We’ll also discuss monomorphization: how the Rust compiler generates optimized, type-specific code for each usage of your generic functions with zero runtime cost. We also demonstrate pattern matching with generic enums, the difference between consuming ownership (self) versus borrowing (&self) in methods, and how trait bounds prevent compile-time errors by ensuring only compatible types can be used.
Related Link:
digikey.com/en/maker/tutorials/2026/intro-to-embedded-rust-part-6-generics-and-traits
Links:
Getting Started with STM32 and Nucleo: youtube.com/watch?v=hyZS2p1tW-g&list=PLEBQazB0HUyRYuzfi4clXsKUSgorErmBv
Introduction to Real-Time Operating Systems (RTOS): youtube.com/watch?v=F321087yYy4&list=PLEBQazB0HUyQ4hAPU1cJED6t3DU0h34bz
Raspberry Pi Pico 2: digikey.com/en/products/detail/raspberry-pi/SC1631/24627142
Learn more:
Maker.io - digikey.com/en/maker
DigiKey’s Blog – TheCircuit digikey.com/en/blog
Connect with DigiKey on Facebook facebook.com/digikey.electronics
And follow us on X: https://x.com/digikey
Product:
digikey.com/en/products/detail/raspberry-pi/SC1631/24627142
digikey.com/en/products/detail/raspberry-pi/SC1632/26241102
digikey.com/en/products/detail/raspberry-pi/SC1633/25862735
digikey.com/en/products/detail/raspberry-pi/SC1634/26241087
digikey.com/en/products/detail/sparkfun-electronics/13314/6797646
digikey.com/en/products/detail/lite-on-inc/LTL-4224/217584
digikey.com/en/products/detail/stackpole-electronics-inc/CF14JT220R/1830334
digikey.com/en/products/detail/te-connectivity-alcoswitch-switches/1825910-6/1632536
digikey.com/en/products/detail/dfrobot/FIT0096/7597069
digikey.com/en/products/detail/adafruit-industries-llc/1957/6827090
digikey.com/en/products/detail/cvilux-usa/DH-20M50055/13175849
Chapters:
0:00 Intro
0:52 Example 1: Generic Function
5:43 Example 2: Traits
8:30 Example 3:Trait Bounds
13:38 Example 4: Generic Struct
16:40 Example 5: Generic Enum
20:51 Embedded Example: Generic LED Driver
26:33 Conclusion
In this tutorial, we cover generics and traits in Rust. Generics allow you to write functions, structs, and enums that work with multiple types without code duplication (similar to templates in C++ but with zero runtime overhead through monomorphization). Traits define shared behavior across different types, acting like interfaces in other languages to create contracts that guarantee specific functionality.
The written guide for this episode can be found here: digikey.com/en/maker/tutorials/2026/intro-to-embedded-rust-part-6-generics-and-traits
The GitHub repository containing the Docker image and example code for this series can be found here: github.com/ShawnHymel/introduction-to-embedded-rust
This guide walks through five key examples demonstrating generics and traits in action. We start with generic functions, showing how a single swap ‹T, U › () function can work with any tuple types instead of writing separate functions for each combination. You'll learn about trait definitions and implementations, creating a Hello trait and implementing it for a Person struct to demonstrate polymorphic behavior.
We also cover trait bounds in detail, explaining how to constrain generic types to only those implementing specific traits. We explore generic structs with the Pair ‹T, U › example, showing how to create data structures that work with any types while maintaining compile-time type safety, and demonstrate generic enums by building a simplified version of Rust's Option ‹T › type.
We’ll also discuss monomorphization: how the Rust compiler generates optimized, type-specific code for each usage of your generic functions with zero runtime cost. We also demonstrate pattern matching with generic enums, the difference between consuming ownership (self) versus borrowing (&self) in methods, and how trait bounds prevent compile-time errors by ensuring only compatible types can be used.
Related Link:
digikey.com/en/maker/tutorials/2026/intro-to-embedded-rust-part-6-generics-and-traits
Links:
Getting Started with STM32 and Nucleo: youtube.com/watch?v=hyZS2p1tW-g&list=PLEBQazB0HUyRYuzfi4clXsKUSgorErmBv
Introduction to Real-Time Operating Systems (RTOS): youtube.com/watch?v=F321087yYy4&list=PLEBQazB0HUyQ4hAPU1cJED6t3DU0h34bz
Raspberry Pi Pico 2: digikey.com/en/products/detail/raspberry-pi/SC1631/24627142
Learn more:
Maker.io - digikey.com/en/maker
DigiKey’s Blog – TheCircuit digikey.com/en/blog
Connect with DigiKey on Facebook facebook.com/digikey.electronics
And follow us on X: https://x.com/digikey
Product:
digikey.com/en/products/detail/raspberry-pi/SC1631/24627142
digikey.com/en/products/detail/raspberry-pi/SC1632/26241102
digikey.com/en/products/detail/raspberry-pi/SC1633/25862735
digikey.com/en/products/detail/raspberry-pi/SC1634/26241087
digikey.com/en/products/detail/sparkfun-electronics/13314/6797646
digikey.com/en/products/detail/lite-on-inc/LTL-4224/217584
digikey.com/en/products/detail/stackpole-electronics-inc/CF14JT220R/1830334
digikey.com/en/products/detail/te-connectivity-alcoswitch-switches/1825910-6/1632536
digikey.com/en/products/detail/dfrobot/FIT0096/7597069
digikey.com/en/products/detail/adafruit-industries-llc/1957/6827090
digikey.com/en/products/detail/cvilux-usa/DH-20M50055/13175849
Chapters:
0:00 Intro
0:52 Example 1: Generic Function
5:43 Example 2: Traits
8:30 Example 3:Trait Bounds
13:38 Example 4: Generic Struct
16:40 Example 5: Generic Enum
20:51 Embedded Example: Generic LED Driver
26:33 Conclusion




![All Wound Up [Maker Update] | Maker.io
This week on Maker Update: on a wing and a prayer, making your own RAM in a shed, corrugated starships, and indestructible PLA parts.
+Show Notes [Maker Update Ep.481]+
=Project of the Week=
Super Capacitor Wind Up Plane by Tom Stanton 0:28
https://www.youtube.com/watch?v 4X6KYlQ7YQ
=More Projects=
Making RAM at Home by Dr. Semiconductor 2:40
https://www.youtube.com/watch?v=h6GWikWlAQA
3d Printed Pinball by 3d Printer Academy 3:30
https://www.youtube.com/watch?v=r7c_iTuHRgs
Cardboard Star Wars by Zach King 4:50
https://www.youtube.com/watch?v=ulVscDewRPI
=Tips & Tools=
Indestructible PLA by Makers Muse 5:24
https://www.youtube.com/watch?v=c7CI6yBTKMc
The Quietest Servo by Will Cogley 5:59
https://www.youtube.com/watch?v=G8TKJH7o5Fs
Shop Servos on DigiKey:
https://www.digikey.com/short/np4n89r0
Repair Box by Duct Tapers Anonymous 6:45
https://www.youtube.com/watch?v=2BwVKB1s4JA
Time of Flight Sensor to 3d Scanner by Henrique Ferrolho 7:19
https://www.youtube.com/watch?v=s32OUzhjf4U
Shop Time of Flight Sensors on DigiKey:
https://www.digikey.com/short/5mbq3573
=DigiKey Spotlight=
How to Choose a Mosfet 7:53
https://www.youtube.com/watch?v=e19derT5z9A
https://www.youtube.com/watch?v=F485AB1B1_Y
#makerupdate
Maker Update is a weekly video series covering news, projects, tips, and events that interest the maker and DIY community.
Find more online:
Blog: http://makerprojectlab.com
Instagram: https://www.instagram.com/makerprojectlab/ All Wound Up [Maker Update] | Maker.io](https://i.ytimg.com/vi/eeGZ0l2yWeY/mqdefault.jpg)




![Seeing Double [Maker Update] | Maker.io
This week on Maker Update: a lamp that’s through the looking glass, a butterfly you can steer, a 3d printed vending machine, and how to use free weights as a battery.
+Show Notes [Maker Update Ep.469]+
=Project of the Week=
Kaleidoscope Lamp by Simone Giertz 0:31
https://www.youtube.com/watch?v=GPSNT5vjSO8
=More Projects=
RC Butterfly by S-DIY 2:56
https://www.youtube.com/watch?v=eLTltRwuGW8
Making Furniture from Tiny Objects by Rachel Maksy 4:01
https://www.youtube.com/watch?v=z90eikSwvhc
3d Printed Vending Machine by DevMode Makes 5:03
https://www.youtube.com/watch?v=iorlgZoYXaQ
=Tips & Tools=
Testing Advanced 3d Printing Materials by Makers Muse 5:43
https://www.youtube.com/watch?v=Lo6UdFKQO0c
Can a Pendulum be a Battery by Tom Stanton 6:22
https://www.youtube.com/watch?v=uqmT1GzRXWI
TrueNAS Deep Dive by Zack Freedman 7:01
https://www.youtube.com/watch?v=n4wDmjEn8Vo
=DigiKey Spotlight=
Embedded Rust by Shawn Hymel 7:45
https://www.youtube.com/watch?v=mz-vW-Ar_GM
#makerupdate
Maker Update is a weekly video series covering news, projects, tips, and events that interest the maker and DIY community.
Find more online:
Blog: http://makerprojectlab.com
Instagram: https://www.instagram.com/makerprojectlab/ Seeing Double [Maker Update] | Maker.io](https://i.ytimg.com/vi/fyR3Dv0BOlo/mqdefault.jpg)
