Show HN: Inception: Automatic Rust Trait Implementation by Induction
github.comHi HN,
I thought this would be a good place to share a little puzzle I've been working on. Inception is a Rust library that helps you share behaviors in Rust using structural induction. Practically, this means that instead of having a derive macro for each behavior, a single derive can be used to enable any number of behaviors. It doesn't do this using runtime reflection, but rather type-level programming - so there is monomorphization across the substructures, and (at least in theory) no greater overhead than with macro expansion.
While there are a lot of things missing still and the current implementation is very suboptimal, I'd say it proves the general concept for common structures. Examples of Clone/Eq/Hash/etc replicas implemented in this way are provided.
The code is not idiomatic, which is my biggest reservation about continuing this work. It was fun to prove, but is not so fun to _improve_, as it feels a bit like swimming upstream. In any case I hope some of you find it interesting!
>Given a type T, if we can prove some property exists for all of T's minimal substructures, and all of T's immediate substructures, then this property must also hold for T itself.
I'm pretty sure people don't like this explanation because it implicitly assumes a directed acyclic graph and a reduction operation that takes a set of T and produces a single composite T.
Oh, that's pretty funny actually.
In retrospect, if I cared about getting peoples' attention I should have mentioned something about "static reflection", or positioned this as more of a direct "threat" to macro expansion (and made it opt-in instead of opt-out, I forgot how frightened people are by any new ability to infer things).
I'm just a coder, not an influencer, though I do have one additional change in mind which borders on sensationalism.