Show HN: FizzBuzz purely in Rust's trait system
github.com
github.com
impl<T: Nat,
Mod3: Nat,
Mod5: Nat,
ShouldFizz: Bool,
ShouldBuzz: Bool,
ShouldFizzBuzz: Bool,
DidBuzz: FizzBuzzType,
DidFizz: FizzBuzzType,
DidFizzBuzz: FizzBuzzType>Interesting implementation of `If`, I had no idea the trait system could be... used... to such extent.
The goal isn't to be concise, I think the goal is literally to just do it in the trait system
If you have a blog, I would like to read about your experiments!
type If<Cond, Then, Else> = <(Then, Else) as If<Cond>>::Output;Rules for actually using this crate: Don't :-).
That said, there are legitimate reasons to implement things at compile time. It means that libraries can create very efficient code that you don't have to write. But like all of powerful capabilities you should beware of misusing them. Like this :-).
https://github.com/doctorn/trait-eval/blob/master/src/lib.rs
But it has been proposed in JEP 303 [1]