Trait-Constrained Enums in Rust

Overview A simple expression language More precise types with GADTs More flexible types with GADTs Encoding GADTs in Rust Type equality witnesses Trait constraint witnesses Using specialisation to recover constraints Why this works Limitations Conclusion Rust doesn’t have GADTs (generalised algebraic data types), but we can get surprisingly close with some creative type-level tricks. This post…