- Adapter Pattern
- Builder Pattern
- Command Pattern
- Composite Pattern
- Decorator Pattern
- Factory Pattern
- Iterator Pattern
- Observer Pattern
- Strategy Pattern
- State Pattern
- Template Method Pattern
Now the book and Rust have changed a lot in the past 2 years, some patterns may have cleaner implementations, but still technical components used in this repo are stainlessly useful.
Though these codes are simple, I think it's a good way to get familiar with Rust, especially some tricks and features only belonged to Rust, like lifetime with references.
Most but not all of the examples are from the book Head First Design Pattern which is reallllly juicy and worth reading.
Some other sources are referred in code comments.
Please run cargo doc --open
in the root of this directory to see the auto-generated fancy documentation.
Jetbrains' IDEs
+ Rust plugin by Jetbrains
For you can see the static type inference of Rust, which is really helpful
In each sub mod of lib.rs
, there is a test mod. You can run the test mod to compile and run codes of specific patterns without bothering running main()
and compiling all codes.
- Implement more patterns
- Implement the tests of State Pattern
- Singleton
- The crate
lazy-static
helps inmain.rs
and it works, but it seems that this dose not work in other mods. - Singleton is discouraged by the community for its global accessibility
- The crate