Rust Trait Runtime Polymorphism in C++ - Eduardo Madrid - CppCon 2025 @CppCon
Rust Trait Runtime Polymorphism in C++ - Eduardo Madrid - CppCon 2025  @CppCon
Uploaded January 2026 | Updated September 2026, 2 weeks ago
cppcon.org
---

Rust Trait Runtime Polymorphism in C++ - Eduardo Madrid - CppCon 2025
---

We built a library to support runtime polymorphism in the style of Rust Traits. C++ libraries ought to provide composable abstractions with zero-overhead, and this library may yield those benefits compared to idiomatic Rust runtime polymorphism (traits). Remarkably, the library also improves upon the very feature of C++ for runtime polymorphism, virtual dispatch. Thus, with this library we can enjoy the benefits of traits knowing we won't have to pay performance or object code size for the privilege.

Still, why would we want to use this design option?

This presentation will illustrate by examples how Traits give us a way to avoid the hard problems of the normal design choice of inheriting from an object-oriented interface. Then, we will study how traits are supported, and how and why performance/object code size can be improved. You may anticipate that part of the reason is that this is a library rather than a programming language feature, and as such, it gives users freedoms that language features inherently deny — more reason to study these choices. Perhaps this new context surfaces improvements to Rust’s trait mechanism.

Looking deeper at traits we see the following:

- For starters, we don’t have to modify already-great types —especially those we don’t own. We just provide the trait functions' implementations separately: no subclassing, no wrappers, and no struggles to retrofit new polymorphism to existing codebases, just new code.
- Inheritance has problems of rigidity, traits void the need to use inheritance
- Traits decouple behaviors from hierarchies of inheritance, allowing clean composition of functionality.
- In particular, no fragile base classes: no challenge of changing a base with unexpected consequences.
- There’s no tight coupling between interfaces and implementations - - Traits are opt-in behavior.
- Dynamic dispatch is explicit and type-safe
- Also polymorphism with value semantics! -

Finally, the programming techniques devised in this framework to support Rust Traits, such as the automatic building of constexpr virtual tables, might be applicable on their own to unrelated things.

We will show how C++ is so powerful that you can incorporate wholesale good ideas from other languages and improve.

---

Slides: github.com/CppCon/CppCon2025/blob/main/Presentations/Rust_Traits_in_Style_for_Cpp.pdf

Work at Hudson River Trading (HRT): tinyurl.com/safxfctf
---

Eduardo Madrid

Eduardo has been working for many years on financial technologies, automated trading in particular, and other areas where performance challenges can be solved in C++. He contributes to open source projects and teaches advanced courses on Software Engineering with emphasis in Generic Programming
---

CppCon is the annual, week-long face-to-face gathering for the entire C++ community. The conference is organized by the C++ community for the community. You will enjoy inspirational talks and a friendly atmosphere designed to help attendees learn from each other, meet interesting people, and generally have a stimulating experience. Taking place this year in Aurora, Colorado, near the Denver airport, and including multiple diverse tracks, the conference will appeal to anyone from C++ novices to experts.
Annual CppCon Conference - cppcon.org
linkedin.com/company/cppcon
https://x.com/cppcon
facebook.com/CppConference
reddit.com/r/cppcon
https://mastodon.social/@CppCon
---

Videos Filmed & Edited by Bash Films: BashFilms.com
YouTube Channel Managed by Digital Medium Ltd: events.digital-medium.co.uk
---

#cpp #cplusplus #cppcon #cppprogramming #cplusplusprogramming #softwaredevelopment #softwareengineering #coding #code #computerscience #technology #technews #programming #programmer
Rust Trait Runtime Polymorphism in C++ - Eduardo Madrid - CppCon 2025Lightning Talk: Cut the boilerplate with C++23 deducing_this - Sarthak Sehgal - CppCon 2025Lightning Talk: Remote Execution Caching Compiler (RECC) for C++ Builds - Shivam Bairoliya - CppConEngineers Are Users Too: A Case Study in Design Thinking for Infrastructure - Grace AlwanThe Joy of C++26 Contracts - Myths, Misconceptions & Defensive Programming - Herb SutterLightning Talk: The UB Detector: constexpr - Andreas Fertig - CppCon 2024Making C++ Safe, Healthy, and Efficient - John Lakos - CppCon 2025Lightning Talk: The Present and Future of Cross-Platform GUI in C++ - Matt Aber - CppCon 2024Building a High-Performance Binary Serialization Format with In-Place Modification - Hamish MorrisonLightweight Operator Fusion Using Data-Centric Function Interfaces in C++ - Manya Bansal - CppConTo Int or to Uint, This is the Question - Alex Dathskovsky - CppCon 2024Lightning Talk: Back When ChatGpt Was Young And Stupid - Andrei Zissu - CppCon 2025
CppCon |

Rust Trait Runtime Polymorphism in C++ - Eduardo Madrid - CppCon 2025

SHARE TO X SHARE TO REDDIT SHARE TO FACEBOOK WALLPAPER