{"id":13648663,"url":"https://github.com/doctorn/trait-eval","last_synced_at":"2025-04-22T11:32:54.495Z","repository":{"id":41368235,"uuid":"266432667","full_name":"doctorn/trait-eval","owner":"doctorn","description":"We all know Rust's trait system is Turing complete, so tell me, why aren't we exploiting this???","archived":false,"fork":false,"pushed_at":"2021-01-31T22:09:34.000Z","size":25,"stargazers_count":367,"open_issues_count":0,"forks_count":8,"subscribers_count":7,"default_branch":"master","last_synced_at":"2025-04-22T03:06:51.446Z","etag":null,"topics":["compile-time","engineering-at-its-best","evaluator"],"latest_commit_sha":null,"homepage":"","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/doctorn.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null},"funding":{"github":["doctorn"]}},"created_at":"2020-05-23T22:52:58.000Z","updated_at":"2025-04-02T09:00:27.000Z","dependencies_parsed_at":"2022-09-16T09:00:56.931Z","dependency_job_id":null,"html_url":"https://github.com/doctorn/trait-eval","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/doctorn%2Ftrait-eval","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/doctorn%2Ftrait-eval/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/doctorn%2Ftrait-eval/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/doctorn%2Ftrait-eval/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/doctorn","download_url":"https://codeload.github.com/doctorn/trait-eval/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250232411,"owners_count":21396640,"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":["compile-time","engineering-at-its-best","evaluator"],"created_at":"2024-08-02T01:04:26.312Z","updated_at":"2025-04-22T11:32:54.166Z","avatar_url":"https://github.com/doctorn.png","language":"Rust","funding_links":["https://github.com/sponsors/doctorn"],"categories":["Rust"],"sub_categories":[],"readme":"# `trait_eval`\n\n[![Crates.io](https://img.shields.io/crates/v/trait_eval.svg?style=plastic)](https://crates.io/crates/trait_eval)\n[![Build Status](https://travis-ci.org/doctorn/trait-eval.svg?branch=master)](https://travis-ci.org/doctorn/trait-eval)\n[![lines of code](https://tokei.rs/b1/github/doctorn/trait-eval)](https://github.com/Aaronepower/tokei)\n![Minimum rustc 1.43](https://img.shields.io/badge/rustc-1.43+-brightgreen.svg)\n\nWe all know Rust's trait system is Turing complete, so tell me, why aren't we exploiting this??? Who needs `const-fn` when we've got a crate like this?!\n\nHonestly, I was too preoccupied with the fact that I could to stop to think whether I actually should.\n\nBelieve it or not, [I even wrote docs for this](https://docs.rs/trait_eval/).\n\n## Example\n\nHere's an eminently readable example where we play FizzBuzz at compile-time!\n\n```rust\ntrait FizzBuzzType {\n    fn show() -\u003e String; // Don't worry about this -- it's just so we can print the result\n}\n\nstruct Fizz;\n\nimpl FizzBuzzType for Fizz {\n    fn show() -\u003e String {\n        \"Fizz\".to_string()\n    }\n}\n\nstruct Buzz;\n\nimpl FizzBuzzType for Buzz {\n    fn show() -\u003e String {\n        \"Buzz\".to_string()\n    }\n}\n\nstruct FizzBuzz;\n\nimpl FizzBuzzType for FizzBuzz {\n    fn show() -\u003e String {\n        \"FizzBuzz\".to_string()\n    }\n}\n\nimpl\u003cT: Nat\u003e FizzBuzzType for T\nwhere\n    T: Eval,\n    \u003cT as Eval\u003e::Output: Display,\n{\n    fn show() -\u003e String {\n        format!(\"{}\", T::eval())\n    }\n}\n\ntrait FizzBuzzEval: Nat {\n    type Result: FizzBuzzType;\n}\n\nimpl\u003cT: Nat,\n    Mod3: Nat,\n    Mod5: Nat,\n    ShouldFizz: Bool,\n    ShouldBuzz: Bool,\n    ShouldFizzBuzz: Bool,\n    DidBuzz: FizzBuzzType,\n    DidFizz: FizzBuzzType,\n    DidFizzBuzz: FizzBuzzType\u003e FizzBuzzEval for T\nwhere\n    T: Mod\u003cThree, Result = Mod3\u003e + Mod\u003cFive, Result = Mod5\u003e,\n    Mod3: Equals\u003cZero, Result = ShouldFizz\u003e,\n    Mod5: Equals\u003cZero, Result = ShouldBuzz\u003e,\n    ShouldFizz: AndAlso\u003cShouldBuzz, Result = ShouldFizzBuzz\u003e,\n    (Fizz, T): If\u003cShouldFizz, Result = DidFizz\u003e,\n    (Buzz, DidFizz): If\u003cShouldBuzz, Result = DidBuzz\u003e,\n    (FizzBuzz, DidBuzz): If\u003cShouldFizzBuzz, Result = DidFizzBuzz\u003e,\n{\n    type Result = DidFizzBuzz;\n}\n\nassert_eq!(\u003cOne as FizzBuzzEval\u003e::Result::show(), \"1\");\nassert_eq!(\u003cTwo as FizzBuzzEval\u003e::Result::show(), \"2\");\nassert_eq!(\u003cThree as FizzBuzzEval\u003e::Result::show(), \"Fizz\");\nassert_eq!(\u003cFour as FizzBuzzEval\u003e::Result::show(), \"4\");\nassert_eq!(\u003cFive as FizzBuzzEval\u003e::Result::show(), \"Buzz\");\nassert_eq!(\u003cSix as FizzBuzzEval\u003e::Result::show(), \"Fizz\");\nassert_eq!(\u003cSeven as FizzBuzzEval\u003e::Result::show(), \"7\");\nassert_eq!(\u003cEight as FizzBuzzEval\u003e::Result::show(), \"8\");\nassert_eq!(\u003cNine as FizzBuzzEval\u003e::Result::show(), \"Fizz\");\nassert_eq!(\u003cTen as FizzBuzzEval\u003e::Result::show(), \"Buzz\");\n\ntype Fifteen = \u003cThree as Times\u003cFive\u003e\u003e::Result;\nassert_eq!(\u003cFifteen as FizzBuzzEval\u003e::Result::show(), \"FizzBuzz\"); // !!!\n```\n\n## Contributing\n\nPlease, for the love of God, don't use this crate. If you must contribute, open a PR.\n\n## Projects using this crate\n\nSome people never listen, huh?\n - [fortraith](https://github.com/Ashymad/fortraith) - Forth implemented in the Rust trait system\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdoctorn%2Ftrait-eval","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdoctorn%2Ftrait-eval","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdoctorn%2Ftrait-eval/lists"}