Back to Browse

🔍 Code With Me in Rust: Alternate implementations of a Trait without using Boxed Trait Objects

172 views
Aug 4, 2025
5:38

In this video, I show an alternative to using a boxed trait object when we want to give an object different behaviors. I'm building a little web server with an SQL datasource which I also want to fake for testing. Using an Enum to hold the alternatives means that I don't need "dyn" and, by using the delegate crate, I get a really clean solution. 🔧 Topics Covered: - How things look with a trait object implementation - An alternative implementation using enums instead - Using the delegate crate to access the behaviors This video is for intermediate to advanced Rust developers who want to write more flexible and performant code without heap allocations or dynamic dispatch. 🔗 Resources: - The delegate crate: https://docs.rs/delegate/ - The video that helped me find this solution: https://www.youtube.com/watch?v=0XFq9K7N9o4 📌 Chapters: 00:00 Introduction 00:17 Problem context 00:29 Boxed trait object solution 01:06 What I don't like about that 01:45 Using an enum instead 03:26 The delegate crate 04:23 Conclusion Don't forget to like, subscribe, and hit the bell icon for more programming explorations! 👍 If this helped you think like a developer, hit like, subscribe, and tap that bell 🔔 so you don’t miss the next part! CHECK OUT MY OTHER VIDEOS: Rust Programming Playlist: https://www.youtube.com/playlist?list=PLZLC5AM_r9AjYwkudkKvO0yHX3zv3sDV2 C Programming Playlist: https://www.youtube.com/playlist?list=PLZLC5AM_r9Ag0CZdGTUm3FWhBDX28B0Dj Intro to Java Playlist: https://www.youtube.com/playlist?list=PLZLC5AM_r9Ajo6LH_-g7dXjZemaQ5QXnV Software Engineering Topics Playlist: https://www.youtube.com/playlist?list=PLZLC5AM_r9AgMHq42vUXHkXEws3JWdnDb

Download

0 formats

No download links available.

🔍 Code With Me in Rust: Alternate implementations of a Trait without using Boxed Trait Objects | NatokHD