Rust Traits vs C++ Concepts
4.3K views · Aug 19, 2022 · Science & Technology
Comments · 15
@bjugdbjk · 4 years ago
U gys r crazy , Amazing rust content !! Thanks a ton.<br>Lately found this fabulous treasure in YouTube.
1
@arshsohi7221 · 4 years ago
Exactly what I needed and was looking for! Thanks!!
@haystackdmilith · 4 years ago
Glad to see more people talking about Rust :)
3
@JamesBlacklock · 4 years ago
So "concepts" seem kinda like Go interfaces: you automatically implement them if your type conforms to the spec. Interesting.
1
@redcrafterlppa303 · 4 years ago
<a href="https://www.youtube.com/watch?v=f68FtmUTl3s&t=1170">19:30</a> we need these anonymous interfaces in rust. It's annoying when you have shared behavior outside your crate and the author didn't define and implement traits. Maybe introduce a keyword that makes a trait bound loose and only looks if the trait could be implemented with an empty impl block.
@3bdo3id · 1 year ago
<a href="https://www.youtube.com/watch?v=f68FtmUTl3s&t=2819">46:59</a><br><br>How can I reach this repo to contribute?
@alienm00sehunter · 4 years ago
So concepts are kind of like Duck Typing?
@9SMTM6 · 4 years ago
I think C++s concepts have, on a theoretical level, a few advantages and a few disadvantages compared to traits. But on a practical level they will sadly probably never be as powerful as Rusts traits.<br><br>There are a few things you didn't entirely follow up on, that empower Rusts traits over C++ concepts. <br><br>One of them is its interaction with virtual dispatch, which I would consider fairly brilliant. C++ has all these confusing rules about virtual functions and virtual Inheritance and the static variants (which can interact strangely). In Rust meanwhile you simply don't differentiate at definition (since you don't have Inheritance), and only the usage determines which variant gets used. Meanwhile elsewhere you get the performance of static dispatch (and the optimizations that allows).<br><br>In other areas they trade blows. For example, you can implement one of your Rust traits for any foreign type. Which you cannot for C++, with C++ you cannot add methods to classes, and you may not have access to everything inside to supplant the methods you would need (not to speak of the complication it would cause to have to handle multiple cases, certainly not helping with compiler errors). But, on the other hand, you what you cannot do with Rust is implement foreign traits for foreign types (ish, there are exceptions), because of coherence rules (in that situation also known as the orphan rules). That is trivial with C++, any type that conforms to the concept is accepted. But that also means false positives that may lead to weird behavior, eg. when a "start" method exists but doesn't do what you expected. Rusts traits are Nominal (though without Inheritance as a base for Polymorphism, but instead ad-hoc adoption with rules for coherence like the ones mentioned above), while C++s concepts are more akin to structural typing.<br><br>While we're on that topic, another thing that trait coherence kindof ruins (for now at least, there are efforts that would help) is that generic implementation of traits you mentioned ("conditional method implementation"). But first a bit of a foundation: As you said, Trait1 + Trait2 is an AND requirement. OR would not make sense in most casss if you think about it: All you know about the generic T is that it implements these trait bounds, and most of the time you would want to use the methods provided by these bounds, having then connected by OR means you can't use either of the methods. As you correctly stated, the way to do OR would be to have 2 seperate implementations. But now we get to the issue: What do you do if a type implements both Trait1 and Trait2? You have 2 different implementations. I'm not certain right now where Rust will complain about that right now, but in any case it's not... Nice.<br><br>You would have to "prefer" one of these implementations above the other one. One way to archive that is with "Negative Trait implementations", which you could add to the trait bounds, and exclude types that implement said traits. But they are not yet available to people without using nightly. They've been that way for long, not sure why actually, gotta look up what's stopping them from being stabilized.<br><br><br>But yeah, in sum, it can be said that C++ concepts and Rust traits have advantages and disadvantages over each other. And C++ would not have been avow to adopt a system akin to Rusts traits retroactively anyways. But crucially, as you stated, C++ hasn't exactly been quick at adopting them anyways, with even many COMPILERS not supporting then yet, and as long as that's a thing there's going to be very little of the rest of the ecosystem using them, as you can't rely on them being present. Even of these issues would be solved at some point, given the past experiences with other features, most APIs still won't adopt being based on Concepts.
2
@rinket7779 · 2 years ago
Anyone who claims C++ concepts are copying Rust traits has serious brain damage - concepts for C++ have been in development for more than 20 years, before Rust was even an idea.
1
Up next

A Firehose of Rust, for busy people who know some C++
Jack O'Connor · 103K views

Conor Hoekstra - Concepts vs Typeclasses vs Traits vs Protocols - Meeting C++ 2020
Meeting Cpp · 5.7K views

Project Structure (Rust for Rustaceans Book Club: Chapter 5)
Rust and Cpp Cardiff Meetup · 463 views

Kent Beck: Software Engineering in the Age of AI | Prodacity 2026
Rise8 · 29K views

Back to Basics: Templates in C++ - Nicolai Josuttis - CppCon 2022
CppCon · 99K views

Back to Basics: Concepts in C++ - Nicolai Josuttis - CppCon 2024
CppCon · 30K views

Episode 3: Variants-as-Code | X-as-Code Webinar Series
X-as-Code with Sphinx-Needs · 61 views

C++ Coroutines Demystified - Phil Nash - ACCU 2025
ACCU Conference · 6.6K views

Fabian Meyer – Onboarding Your Agent: How eventim Integrates Agentic Engineering
Agentic Hamburg · 37 views

Operating Systems Book Club: Introduction + Processes
Rust and Cpp Cardiff Meetup · 183 views

The Good And Bad Of C++ As A Rust Dev
The PrimeTime · 125K views

Async (Rust for Rustaceans Book Club: Chapter 8)
Rust and Cpp Cardiff Meetup · 747 views

CppCon 2018: Stoyan Nikolov “OOP Is Dead, Long Live Data-oriented Design”
CppCon · 269K views

C++ Coroutines and Structured Concurrency in Practice - Dmitry Prokoptsev - CppCon 2024
CppCon · 12K views

Testing Elixir: From Doctests to OTP and Property-Based
Montreal Elixir · 66 views

[AI & DS] Lecture 24/09/2026 part 1
Stefano Mariani · 17 views

2026 09 16 01
Nathan Hung · 13 views

When C++ Style Guides Contradict - Nicolai Josuttis - CppCon 2019
CppCon · 25K views

All Rust features explained
Let's Get Rusty · 484K views

[CODAI 2026] Maxim Zaks - Solving the Multi-Platform Problem with Mojo
Michael J. Klaiber · 18 views

A Friendly Introduction to Rust for C++ Developers - Hendrik Niemeyer - ACCU 2022
ACCU Conference · 9.5K views

Traits in Rust
Let's Get Rusty · 149K views

Template Metaprogramming: Type Traits (part 1 of 2) - Jody Hagins - CppCon 2020
CppCon · 74K views

[SD] Maxim Zaks - Solving the Multi-Platform Problem with Mojo
Michael J. Klaiber · 27 views

Unsafe Rust (Rust for Rustaceans Book Club: Chapter 9)
Rust and Cpp Cardiff Meetup · 362 views

LaCiPv3Sand challenge
LaCIPv3 2026 · 238 views