{"id":13671799,"url":"https://github.com/fadeevab/design-patterns-rust","last_synced_at":"2025-05-15T01:04:30.217Z","repository":{"id":57884956,"uuid":"515669804","full_name":"fadeevab/design-patterns-rust","owner":"fadeevab","description":"Rust examples for all 23 classic GoF design patterns, and even a little more","archived":false,"fork":false,"pushed_at":"2025-01-01T17:16:57.000Z","size":633,"stargazers_count":1007,"open_issues_count":0,"forks_count":80,"subscribers_count":19,"default_branch":"main","last_synced_at":"2025-04-03T03:31:34.456Z","etag":null,"topics":["design-patterns","rust"],"latest_commit_sha":null,"homepage":"","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/fadeevab.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-07-19T16:53:16.000Z","updated_at":"2025-04-01T10:08:31.000Z","dependencies_parsed_at":"2025-01-15T03:53:23.948Z","dependency_job_id":"444e13d2-5acb-4a29-9e8c-50d8b2188a69","html_url":"https://github.com/fadeevab/design-patterns-rust","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fadeevab%2Fdesign-patterns-rust","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fadeevab%2Fdesign-patterns-rust/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fadeevab%2Fdesign-patterns-rust/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fadeevab%2Fdesign-patterns-rust/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/fadeevab","download_url":"https://codeload.github.com/fadeevab/design-patterns-rust/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248166853,"owners_count":21058481,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["design-patterns","rust"],"created_at":"2024-08-02T09:01:19.059Z","updated_at":"2025-04-10T06:15:38.156Z","avatar_url":"https://github.com/fadeevab.png","language":"Rust","funding_links":[],"categories":["Rust","Design Pattern","Programming languages"],"sub_categories":["Rust"],"readme":"[![Design Patterns in Rust](https://github.com/fadeevab/design-patterns-rust/workflows/Test%20All%20Patterns/badge.svg)](https://github.com/fadeevab/design-patterns-rust)\n\n# Design Patterns in Rust\n\n[\u003cimg width=\"150\" height=\"150\" src=\"https://avatars.githubusercontent.com/u/8557932?s=200\u0026v=4\" align=\"left\" /\u003e](https://refactoring.guru)\n[\u003cimg width=\"150\" height=\"150\" src=\"https://www.rust-lang.org/logos/rust-logo-512x512.png\" style=\"padding-left:20px\" /\u003e](https://www.rust-lang.org/)\n\nThis repository contains **Rust** 🦀 examples for **all 23 classic GoF design\npatterns**, and even a little more.\n\nAll examples are designed to introduce _practical applicability_ in the\n**Rust** language. There are _conceptual_ and _real-world_ examples.\nIn both cases, Rust idiomatic ways of code development and all the specifics\nare taken into account.\n\nThe repository is developed to be a part of the\n[Refactoring.Guru](https://refactoring.guru/design-patterns) project.\n\n## 🔧 Requirements\n\nThese examples have been tested with a _stable_ `rustc 1.82` (2021 edition).\n\nAll examples can be launched via the command line, using `cargo` as follows:\n\n```bash\ncargo run --bin adapter\n```\n\nEach target name can be found in `Cargo.toml` of each example:\n\n```toml\n[[bin]]\nname = \"adapter\"\npath = \"main.rs\"\n```\n\nAlso, the examples contain a **README.md** with instructions and additional explanations.\n\n## ✅ List of Examples\n\n```bash\ncargo run --bin chain-of-responsibility\ncargo run --bin command\ncargo run --bin iterator\ncargo run --bin mediator-top-down\ncargo run --bin mediator-rc-refcell\ncargo run --bin memento\ncargo run --bin memento-serde\ncargo run --bin observer\ncargo run --bin state\ncargo run --bin strategy\ncargo run --bin strategy-func\ncargo run --bin template-method\ncargo run --bin visitor\ncargo run --bin abstract-factory\ncargo run --bin abstract-factory-dyn\ncargo run --bin builder\ncargo run --bin factory-method-maze-game\ncargo run --bin factory-method-render-dialog\ncargo run --bin prototype\ncargo run --bin simple-factory\ncargo run --bin singleton-local\ncargo run --bin singleton-lazy\ncargo run --bin singleton-mutex\ncargo run --bin singleton-once\ncargo run --bin singleton-logger\ncargo run --bin static-creation-method\ncargo run --bin adapter\ncargo run --bin bridge\ncargo run --bin composite\ncargo run --bin decorator\ncargo run --bin facade\ncargo run --bin flyweight\ncargo run --bin proxy\n```\n\nSome examples have visual output.\n\n| Flyweight | State | Command |\n| --------- | ----- | ------- |\n| [\u003cimg width=\"150\" src=\"structural/flyweight/res/forest.svg\"/\u003e](structural/flyweight) | [\u003cimg width=\"246\" src=\"behavioral/state/images/playing.png\"/\u003e](behavioral/state) | [\u003cimg width=\"246\" src=\"behavioral/command/res/editor.png\"/\u003e](behavioral/command) |\n\n## 💡 Notes\n\nInterestingly, in Rust:\n\n1. Almost all **structural** and **creational** patterns can be implemented\n   using generics, hence, _static dispatch_.\n2. Most **behavioral** patterns can NOT be implemented using static dispatch,\n   instead, they can be implemented only via _dynamic dispatch_.\n\nA well-thought pattern classification fits the Rust language design perfectly\nas \"behavior\" is dynamic in nature and \"structure\" is static.\n\nSome patterns are really easy to implement in Rust, mostly\n_creational_ ones, e.g.\n[Prototype](creational/prototype),\n[Static Creation Method](creational/static-creation-method/).\n\nThe [Mediator](behavioral/mediator) _behavioral_ pattern\nis the hardest to implement with Rust, considering Rust's specific ownership\nmodel with strict borrow checker rules.\n\n## License\n\nThis work is licensed under a Creative Commons Attribution-NonCommercial-NoDerivatives 4.0 International License.\n\n\u003ca rel=\"license\" href=\"http://creativecommons.org/licenses/by-nc-nd/4.0/\"\u003e\u003cimg alt=\"Creative Commons License\" style=\"border-width:0\" src=\"https://i.creativecommons.org/l/by-nc-nd/4.0/80x15.png\" /\u003e\u003c/a\u003e\n\n## Credits\n\nAuthors: Alexander Fadeev ([@fadeevab](https://github.com/fadeevab)).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffadeevab%2Fdesign-patterns-rust","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffadeevab%2Fdesign-patterns-rust","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffadeevab%2Fdesign-patterns-rust/lists"}