Rust Traits In C++
summary
Shows a concrete path to get Rust Traits–style runtime polymorphism in C++ by building custom virtual table structures and concrete value managers inside a type‑erasure framework (the Type Erasure / sue any family). Implements a serialize affordance with function pointers, ownership (destruct/move/copy), and value semantics, emits compact assembly in Compiler Explorer, and claims performance that matches or beats classic virtual inheritance. Uses small‑buffer optimization to avoid heap hits and demonstrates runnable code that compiles and executes.
AI-written summary · about
chapters (11)
- 0:00Introduction
- 7:24Runtime polymorphism basics
- 13:23Inheritance for subtyping problems
- 18:44Serialization as polymorphism
- 22:37Rust traits for subtyping
- 27:11Type erasure in C++
- 33:09Virtual tables for dispatch
- 43:07UI binding in practice
- 45:38Live demo on Compiler Explorer
- 53:51C++ type erasure vs Rust traits
- 55:34Conclusion
related talks
01h 22mRust for the C++ Programmer
01h 29mA Friendly Introduction to Rust for C++ Developers
49mPolymorphism != Virtual: Easy, Flexible Runtime Polymorphism Without Inheritance
33mReplacing #[cfg] with Traits: The Inlinable Dyn Extension Trait Pattern
01h 25mC++ Concepts vs Rust Traits vs Haskell Typeclasses vs Swift Protocols
58mRust for The Curious C++ Developers
58mBetter Code: Runtime Polymorphism
01h 07mDynamic Polymorphism With Code Injection and Metaclasses
