doctorn / Trait Eval
Licence: mit
We all know Rust's trait system is Turing complete, so tell me, why aren't we exploiting this???
Stars: ✭ 325
Programming Languages
rust
11053 projects
Labels
Projects that are alternatives of or similar to Trait Eval
d rive
c++17 compile time math(derivation/integration)
Stars: ✭ 16 (-95.08%)
Mutual labels: compile-time
Rugby
🏈 Cache CocoaPods for faster rebuild and indexing Xcode project
Stars: ✭ 448 (+37.85%)
Mutual labels: compile-time
BuildTimeLogger-for-Xcode
A console app for logging Xcode build times and presenting them in a notification
Stars: ✭ 43 (-86.77%)
Mutual labels: compile-time
ctrt
Compile-Time Ray Tracer in Rust ported from C++
Stars: ✭ 82 (-74.77%)
Mutual labels: compile-time
nimly
Lexer Generator and Parser Generator as a Library in Nim.
Stars: ✭ 113 (-65.23%)
Mutual labels: compile-time
units
A lightweight compile-time, header-only, dimensional analysis and unit conversion library built on c++11 with no dependencies
Stars: ✭ 17 (-94.77%)
Mutual labels: compile-time
uninttp
A universal type for non-type template parameters for C++20 or later.
Stars: ✭ 16 (-95.08%)
Mutual labels: compile-time
data-mediator
a data mediator framework bind callbacks for any property
Stars: ✭ 66 (-79.69%)
Mutual labels: compile-time
ghostwriter
Solutions for instrumenting application flow tracking API calls into an existing code base in a non-invasive way
Stars: ✭ 17 (-94.77%)
Mutual labels: compile-time
AnnotationInject
Compile-time Swift dependency injection annotations
Stars: ✭ 40 (-87.69%)
Mutual labels: compile-time
metric
This library provides zero-cost dimensional analysis for safe, unit-aware numeric computations in Rust.
Stars: ✭ 23 (-92.92%)
Mutual labels: compile-time
nim-gatabase
Connection-Pooling Compile-Time ORM for Nim
Stars: ✭ 103 (-68.31%)
Mutual labels: compile-time
oxorany
obfuscated any constant encryption in compile time on any platform
Stars: ✭ 155 (-52.31%)
Mutual labels: compile-time
refuel
Lightweight dependency injection engine and DI-driven tools.
Stars: ✭ 21 (-93.54%)
Mutual labels: compile-time
Unchained
A fully type safe, compile time only units library.
Stars: ✭ 70 (-78.46%)
Mutual labels: compile-time
Revisited
🧑🤝🧑 The visitor pattern revisited. An inheritance-aware acyclic visitor template, any and any-function templates.
Stars: ✭ 14 (-95.69%)
Mutual labels: compile-time
static-string-cpp
Compile-time string manipulation library for modern C++
Stars: ✭ 34 (-89.54%)
Mutual labels: compile-time
compile-time-perf
Measures high-level timing and memory usage metrics during compilation
Stars: ✭ 64 (-80.31%)
Mutual labels: compile-time
trait_eval
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.
Example
Here's an eminently readable example where we play FizzBuzz at compile-time!
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<T: Nat> FizzBuzzType for T
where
T: Eval,
<T as Eval>::Output: Display,
{
fn show() -> String {
format!("{}", T::eval())
}
}
trait FizzBuzzEval: Nat {
type Result: FizzBuzzType;
}
impl<T: Nat,
Mod3: Nat,
Mod5: Nat,
ShouldFizz: Bool,
ShouldBuzz: Bool,
ShouldFizzBuzz: Bool,
DidBuzz: FizzBuzzType,
DidFizz: FizzBuzzType,
DidFizzBuzz: FizzBuzzType> FizzBuzzEval for T
where
T: Mod<Three, Result = Mod3> + Mod<Five, Result = Mod5>,
Mod3: Equals<Zero, Result = ShouldFizz>,
Mod5: Equals<Zero, Result = ShouldBuzz>,
ShouldFizz: AndAlso<ShouldBuzz, Result = ShouldFizzBuzz>,
(Fizz, T): If<ShouldFizz, Result = DidFizz>,
(Buzz, DidFizz): If<ShouldBuzz, Result = DidBuzz>,
(FizzBuzz, DidBuzz): If<ShouldFizzBuzz, Result = DidFizzBuzz>,
{
type Result = DidFizzBuzz;
}
assert_eq!(<One as FizzBuzzEval>::Result::show(), "1");
assert_eq!(<Two as FizzBuzzEval>::Result::show(), "2");
assert_eq!(<Three as FizzBuzzEval>::Result::show(), "Fizz");
assert_eq!(<Four as FizzBuzzEval>::Result::show(), "4");
assert_eq!(<Five as FizzBuzzEval>::Result::show(), "Buzz");
assert_eq!(<Six as FizzBuzzEval>::Result::show(), "Fizz");
assert_eq!(<Seven as FizzBuzzEval>::Result::show(), "7");
assert_eq!(<Eight as FizzBuzzEval>::Result::show(), "8");
assert_eq!(<Nine as FizzBuzzEval>::Result::show(), "Fizz");
assert_eq!(<Ten as FizzBuzzEval>::Result::show(), "Buzz");
type Fifteen = <Three as Times<Five>>::Result;
assert_eq!(<Fifteen as FizzBuzzEval>::Result::show(), "FizzBuzz"); // !!!
Contributing
Please, for the love of God, don't use this crate. If you must contribute, open a PR.
Projects using this crate
Some people never listen, huh?
- fortraith - Forth implemented in the Rust trait system
Note that the project description data, including the texts, logos, images, and/or trademarks,
for each open source project belongs to its rightful owner.
If you wish to add or remove any projects, please contact us at [email protected].