π Code With Me in Rust: Implementing the Strategy Pattern with Enums and Function Pointers
Continuing in my exploration of Rust. In order to continue to learn to think in Rust, I wanted to see what it would take to build an OO pattern (in particular, the Strategy Pattern) in Rust. That led me to three different implementations of the strategy behaviors: one that used function pointers and two that embedded those behaviors in an Enum. I think the Enum solution is very clear and concise and puts all of the behaviors in the same place. That seems like the Rusti-est solution, but let me know what you think! π Resources: - https://refactoring.guru/design-patterns/strategy/rust/example - How do I store a closure in a struct: https://stackoverflow.com/questions/27831944/how-do-i-store-a-closure-in-a-struct-in-rust π Chapters: 00:00 Introduction 00:30 Problem set up 01:15 The Rust solution using Traits 02:56 Attempting to embed the behaviors using closures 04:15 Using Function pointers for the behaviors 08:06 Ah-ha! Enums!!! 08:40 Enum solution #1 10:10 Enum solution #2 11:13 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 formatsNo download links available.