How to stop fighting with coherence and star writing context-generic trait impls
summary
Proposes Context-Generic Programming (CGP) and a released CGP30 crate that generates provider traits and type-level lookup tables so multiple overlapping, formerly-illegal trait implementations compile as distinct providers; uses macros like CGB component and delegate components macro to wire providers into a concrete context. Demonstrated on a messaging library where switching the context changes serialization (hex vs base64) without touching library code; works today but has steep learning curve and noisy error messages.
AI-written summary · about
chapters (15)
- 0:00Introduction
- 1:14Rust trait system and coherence
- 5:49Hash table problem and coherence
- 8:59Existing coherence solutions
- 11:47Specialization limitations
- 13:51Remote trait pattern with Serde
- 15:56Provider traits bypass coherence
- 19:47Context and implicit parameters
- 23:44Context-driven programming
- 24:48CGP30 crate and compatibility
- 28:58Demo of modular serialization
- 33:13Hash problem solved with CGP
- 34:39CGP use cases and future
- 35:20CGP challenges and learning
- 37:06Q&A
related talks
01h 39m“Concepts: The Future of Generic Programming (the future is here)”
45mBoost Your Intra-Process Communication Programs With C++20 & Contract-Concept-Implementation Pattern
01h 07mC++20 Concepts: A Day in the Life
22mMoebius: Metaprogramming using Contextual Types
01h 47mFunctional C++
52mConcepts: The Future of Generic Programming
01h 48m“Meta: Thoughts on generative C++”
57mA Glimpse of Trygve: From Class-oriented Programming to Real OO
