Heterogeneous Lists in Rust and Their Superpowers
summary
Shows how to use heterogeneous lists (an FP-style HList) in Rust to emulate missing features like structural typing and variadic generics. Demonstrates concrete patterns for converting between structs with similar field sets without boilerplate, extracting arbitrary fields from JSON for many field combinations without writing per-combination types, and composing types with shared generic behavior so the correct variant is chosen by the desired result type — all type-safe, zero-cost at runtime, and without unsafe code.
AI-written summary · about
chapters (17)
- 0:00Introduction
- 1:50HList basics
- 3:38JSON parsing problem
- 8:32Defining HList in Rust
- 10:00HList macros
- 12:10Extracting fields
- 13:16Structural typing
- 15:02Generic conversion
- 17:12Field name tracking
- 21:30Multiple field extraction
- 24:01Index extraction
- 27:18Usage examples
- 30:10Advanced extraction
- 33:40Transforming structures
- 35:46Diesel ORM use case
- 36:53Summary
- 37:39Q&A
