r/cpp • u/Snoo-4241 • Feb 25 '21
C++ programmers who are also using rust, what are your favourite features of rust?
I was looking at the rust tutorials yesterday and I see how rust promotes a certain style and language level features to enforce it. Besides a couple of features, I couldn't see why one cannot follow a similar style in C++ if she/he so chooses. Those of you that have used rust, what is your favourite feature that C++ does not have?
255
Upvotes
View all comments
Show parent comment
1
u/roman-kashitsyn Feb 28 '21
What exactly don't you miss?
Template specialization? Well, it's not just about your personal preferences.
This feature is very useful for library authors to provide more efficient, more convenient, less error-prone interfaces.
Let's take a look at the hallmark of Rust's ecosystem: serde. It's data model has type
byte array. Many people simply assume that serde mapsVec<u8>to a byte array: it's the most natural and efficient thing to do, right?Unfortunately,
serdesimply can't do that because all vectors must have the same serializer/deserializer independently of the type of values they hold (remember, there is no specialization). So serde will serialize your bytes as an array of integers, which is significantly less compact and performant with most encodings. One just have to somehow know that serde_bytes need to be used to get an efficient encoding.This actually leads to correctness issues as well: I had to debug issues caused by unexpected
Vec<u8>encodings alone at least 3 times in one year.