GitHub repo: https://github.com/fadeevab/design-patterns-rust
My repository contains unique Rust examples covering all 23 GoF classic design patterns. It already has ~100⭐.
The repository contains an exhausting list of design pattern examples in Rust. I rigorously worked on each pattern to showcase a good meaningful way to apply each of them specifically in Rust.
I wanted to challenge the Rust language specifically on whether it can adapt literally any OOP concept existing at the moment, and it passed the challenge.
There are examples with visual output, like Flyweight: drawing a forest of million trees 🌳.
The Mediator behavioral pattern is the hardest to implement with Rust, considering Rust's specific ownership model with strict borrow checker rules.
Interestingly, in Rust:
- Almost all structural and creational patterns can be implemented using generics, hence, static dispatch.
- Most behavioral patterns can NOT be implemented using static dispatch, instead, they can be implemented only via dynamic dispatch.
A well-thought pattern classification fits the Rust language design perfectly as "behavior" is dynamic in nature and "structure" is static.