Skip to content

Commit 3666af4

Browse files
authored
Merge pull request #9 from contextgeneric/extensible-datatypes-part-4
Blog post for Extensible Data Types Part 4: Implementing Extensible Variants
2 parents 93f60d5 + 73e911d commit 3666af4

7 files changed

+1543
-520
lines changed

content/_index.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ Read the blog series **Programming Extensible Data Types in Rust with CGP** for
1717
- [**Part 1: Modular App Construction and Extensible Builders**](/blog/extensible-datatypes-part-1/)
1818
- [**Part 2: Modular Interpreters and Extensible Visitors**](/blog/extensible-datatypes-part-2/)
1919
- [**Part 3: Implementing Extensible Records**](/blog/extensible-datatypes-part-3/)
20+
- [**Part 4: Implementing Extensible Variants**](/blog/extensible-datatypes-part-4/)
2021

2122
# Overview
2223

content/blog/2025-07-07-extensible-datatypes-part-1.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ This article is the first in a five-part series exploring the examples and imple
3838

3939
[**Part 3: Implementing Extensible Records**](/blog/extensible-datatypes-part-3) – Here, we walk through the internal mechanics behind extensible records. We show how CGP supports the modular builder pattern demonstrated in Part 1 through its underlying type and trait machinery.
4040

41-
**Part 4: Implementing Extensible Variants** – This part mirrors Part 3, but for extensible variants. We examine how extensible variants are implemented, and compare the differences and similarities between extensible records and variants.
41+
[**Part 4: Implementing Extensible Variants**](/blog/extensible-datatypes-part-4) – This part mirrors Part 3, but for extensible variants. We examine how extensible variants are implemented, and compare the differences and similarities between extensible records and variants.
4242

4343
# Feature Highlighs
4444

content/blog/2025-07-09-extensible-datatypes-part-2.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ In this second part of the series, we will explore the use of **extensible varia
2626

2727
[**Part 3: Implementing Extensible Records**](/blog/extensible-datatypes-part-3) – Here, we walk through the internal mechanics behind extensible records. We show how CGP supports the modular builder pattern demonstrated in Part 1 through its underlying type and trait machinery.
2828

29-
**Part 4: Implementing Extensible Variants** – This part mirrors Part 3, but for extensible variants. We examine how extensible variants are implemented, and compare the differences and similarities between extensible records and variants.
29+
[**Part 4: Implementing Extensible Variants**](/blog/extensible-datatypes-part-4) – This part mirrors Part 3, but for extensible variants. We examine how extensible variants are implemented, and compare the differences and similarities between extensible records and variants.
3030

3131
# Extending the Visitor Pattern
3232

content/blog/2025-07-12-extensible-datatypes-part-3.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ We will first explore the implementation of extensible records in this part, fol
3434

3535
**Part 3: Implementing Extensible Records** (this post) – Here, we walk through the internal mechanics behind extensible records. We show how CGP supports the modular builder pattern demonstrated in Part 1 through its underlying type and trait machinery.
3636

37-
**Part 4: Implementing Extensible Variants** – This part mirrors Part 3, but for extensible variants. We examine how extensible variants are implemented, and compare the differences and similarities between extensible records and variants.
37+
[**Part 4: Implementing Extensible Variants**](/blog/extensible-datatypes-part-4) – This part mirrors Part 3, but for extensible variants. We examine how extensible variants are implemented, and compare the differences and similarities between extensible records and variants.
3838

3939
# Underlying Theory
4040

@@ -726,7 +726,7 @@ If any part of this explanation remains unclear, it might be helpful to paste th
726726

727727
With the `BuildFrom` trait in place, we can now explore how CGP implements generalized **builder dispatchers** that enable flexible and reusable ways to assemble struct fields from various sources.
728728

729-
## `BuildWithHandlers` Trait
729+
## `BuildWithHandlers` Provider
730730

731731
In [earlier examples](/blog/extensible-datatypes-part-1/#builder-dispatcher), we used a utility called `BuildAndMergeOutputs` to combine outputs from multiple builder providers such as `BuildSqliteClient`, `BuildHttpClient`, and `BuildOpenAiClient`. Under the hood, `BuildAndMergeOutputs` is built upon a more fundamental dispatcher named `BuildWithHandlers`. The implementation of this dispatcher looks like the following:
732732

@@ -965,7 +965,7 @@ With this setup, `BuildAndMergeOutputs` can now be used like any other CGP provi
965965

966966
The key benefit of this pattern is that it avoids boilerplate while preserving type safety. Whenever a provider's implementation is simply a thin wrapper around another provider with some added constraints, it's much more convenient to use `DelegateComponent` via `delegate_components!` than to implement the provider trait manually.
967967

968-
## Type-Level CGP Metaprogramming
968+
## Type-Level Metaprogramming
969969

970970
The technique we just explored — wrapping providers and using `delegate_components!` — can be seen as a form of **metaprogramming** in CGP. Here, we’re leveraging **type-level programming** not just within CGP’s core component abstractions like `DelegateComponent`, but also as a tool for *programmatically defining component wiring* through the use of generic parameters and trait constraints.
971971

0 commit comments

Comments
 (0)