Union Types in Rust with Type-Level Lists Shun Kashiwa&39;s Blog

Metadata

Source URL:: https://blog.shun-k.dev/posts/rust-union-types/
Topics:: #rust, #union-types, #types, #type-level-recursion


In this article, I will discuss a technique to represent union types in Rust. With type-level lists, we can express a set of types, and through trait resolution, determine if a particular type is part of a set or if one set is a subset of another. The core of this technique is a recursive operation on type-level lists. To avoid conflicting implementations of traits, we will add a marker type that express the depth of recursion.

Highlights