# `trait_eval` [![Crates.io](https://img.shields.io/crates/v/trait_eval.svg?style=plastic)](https://crates.io/crates/trait_eval) [![Build Status](https://travis-ci.org/doctorn/trait-eval.svg?branch=master)](https://travis-ci.org/doctorn/trait-eval) [![lines of code](https://tokei.rs/b1/github/doctorn/trait-eval)](https://github.com/Aaronepower/tokei) ![Minimum rustc 1.43](https://img.shields.io/badge/rustc-1.43+-brightgreen.svg) We 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?! Honestly, I was too preoccupied with the fact that I could to stop to think whether I actually should. Believe it or not, [I even wrote docs for this](https://docs.rs/trait_eval/0.1.0/trait_eval/). ## Example Here's an eminently readable example where we play FizzBuzz at compile-time! ```rust trait FizzBuzzType { fn show() -> String; // Don't worry about this -- it's just so we can print the result } struct Fizz; impl FizzBuzzType for Fizz { fn show() -> String { "Fizz".to_string() } } struct Buzz; impl FizzBuzzType for Buzz { fn show() -> String { "Buzz".to_string() } } struct FizzBuzz; impl FizzBuzzType for FizzBuzz { fn show() -> String { "FizzBuzz".to_string() } } impl FizzBuzzType for T where T: Eval, ::Output: Display, { fn show() -> String { format!("{}", T::eval()) } } trait FizzBuzzEval: Nat { type Result: FizzBuzzType; } impl FizzBuzzEval for T where T: Mod + Mod, Mod3: Equals, Mod5: Equals, ShouldFizz: AndAlso, (Fizz, T): If, (Buzz, DidFizz): If, (FizzBuzz, DidBuzz): If, { type Result = DidFizzBuzz; } assert_eq!(::Result::show(), "1"); assert_eq!(::Result::show(), "2"); assert_eq!(::Result::show(), "Fizz"); assert_eq!(::Result::show(), "4"); assert_eq!(::Result::show(), "Buzz"); assert_eq!(::Result::show(), "Fizz"); assert_eq!(::Result::show(), "7"); assert_eq!(::Result::show(), "8"); assert_eq!(::Result::show(), "Fizz"); assert_eq!(::Result::show(), "Buzz"); type Fifteen = >::Result; assert_eq!(::Result::show(), "FizzBuzz"); // !!! ``` ## Contributing Please, for the love of God, don't use this crate. If you must contribute, open a PR.