Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Rust examples for all 23 classic GoF design patterns, and even a little more

License

NotificationsYou must be signed in to change notification settings

fadeevab/design-patterns-rust

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Design Patterns in Rust

Design Patterns in Rust

This repository containsRust 🦀 examples forall 23 classic GoF designpatterns, and even a little more.

All examples are designed to introducepractical applicability in theRust language. There areconceptual andreal-world examples.In both cases, Rust idiomatic ways of code development and all the specificsare taken into account.

The repository is developed to be a part of theRefactoring.Guru project.

🔧 Requirements

These examples have been tested with astablerustc 1.82 (2021 edition).

All examples can be launched via the command line, usingcargo as follows:

cargo run --bin adapter

Each target name can be found inCargo.toml of each example:

[[bin]]name ="adapter"path ="main.rs"

Also, the examples contain aREADME.md with instructions and additional explanations.

✅ List of Examples

cargo run --bin chain-of-responsibilitycargo run --bincommandcargo run --bin iteratorcargo run --bin mediator-top-downcargo run --bin mediator-rc-refcellcargo run --bin mementocargo run --bin memento-serdecargo run --bin observercargo run --bin statecargo run --bin strategycargo run --bin strategy-funccargo run --bin template-methodcargo run --bin visitorcargo run --bin abstract-factorycargo run --bin abstract-factory-dyncargo run --bin buildercargo run --bin factory-method-maze-gamecargo run --bin factory-method-render-dialogcargo run --bin prototypecargo run --bin simple-factorycargo run --bin singleton-localcargo run --bin singleton-lazycargo run --bin singleton-mutexcargo run --bin singleton-oncecargo run --bin singleton-loggercargo run --bin static-creation-methodcargo run --bin adaptercargo run --bin bridgecargo run --bin compositecargo run --bin decoratorcargo run --bin facadecargo run --bin flyweightcargo run --bin proxy

Some examples have visual output.

FlyweightStateCommand

💡 Notes

Interestingly, in Rust:

  1. Almost allstructural andcreational patterns can be implementedusing generics, hence,static dispatch.
  2. Mostbehavioral patterns can NOT be implemented using static dispatch,instead, they can be implemented only viadynamic dispatch.

A well-thought pattern classification fits the Rust language design perfectlyas "behavior" is dynamic in nature and "structure" is static.

Some patterns are really easy to implement in Rust, mostlycreational ones, e.g.Prototype,Static Creation Method.

TheMediatorbehavioral patternis the hardest to implement with Rust, considering Rust's specific ownershipmodel with strict borrow checker rules.

License

This work is licensed under a Creative Commons Attribution-NonCommercial-NoDerivatives 4.0 International License.

Creative Commons License

Credits

Authors: Alexander Fadeev (@fadeevab).

About

Rust examples for all 23 classic GoF design patterns, and even a little more

Topics

Resources

License

Stars

Watchers

Forks

Contributors5

Languages


[8]ページ先頭

©2009-2025 Movatter.jp