Programming Extensible Data Types in Rust with CGP – Part 1: Modular App Constr

3 todsacerdoti 1 7/8/2025, 7:16:20 AM contextgeneric.dev ↗

Comments (1)

maybevoid · 1h ago
Hi everyone, I’m excited to share the latest progress in Context-Generic Programming (CGP), which now includes support for extensible records and variants in Rust.

For those of you coming from functional languages, this development effectively brings the power of datatype-generic programming, structural typing, row polymorphism and polymorphic variants to Rust. These are advanced type system features commonly found in languages like Haskell, PureScript and OCaml, and their availability in CGP represents a major leap in what is possible with the type system in Rust.

If you're new to the concept, extensible data types allow us to read from, construct, and extract data from a generic struct or enum without needing to know its concrete type definition. This opens the door to powerful design patterns, such as building generic builders or visitors that can operate flexibly over a wide range of data structures.

In the first post of this new blog series, I walk through a simple example that shows how to use extensible builders to construct an application context in a modular way.

I’d love to hear what you think — especially whether the approach feels practical or insightful for your own work. I’ll be sharing more updates over the next few days, so stay tuned!