Rust examples for all 23 classic GoF design patterns, and even a little more
Rust examples for all 23 classic GoF design patterns, and even a little more
This repository contains Rust examples for all 23 classic GoF design patterns, and even a little more.
All examples are designed to introduce practical applicability in the Rust language. There are conceptual and real-world examples. In both cases, Rust idiomatic ways of code development and all the specifics are taken into account.
The repository is developed to be a part of the Refactoring.Guru project.
These examples have been tested with a stable rustc 1.82 (2021 edition).
All examples can be launched via the command line, using cargo as follows:
cargo run --bin adapterEach target name can be found in Cargo.toml of each example:
[[bin]]
name = "adapter"
path = "main.rs"Also, the examples contain a README.md with instructions and additional explanations.
…Some examples have visual output.
| Flyweight | State | Command |
|---|---|---|
Interestingly, in Rust:
A well-thought pattern classification fits the Rust language design perfectly as "behavior" is dynamic in nature and "structure" is static.
Some patterns are really easy to implement in Rust, mostly creational ones, e.g. Prototype, Static Creation Method.
The Mediator behavioral pattern is the hardest to implement with Rust, considering Rust's specific ownership model with strict borrow checker rules.
This work is licensed under a Creative Commons Attribution-NonCommercial-NoDerivatives 4.0 International License.
Authors: Alexander Fadeev (@fadeevab).
No open issues yet, or sync has not completed.