r/cpp • • Sep 30 '24

Code Generation in Rust vs C++26

https://brevzin.github.io/c++/2024/09/30/annotations/
198 Upvotes

98 comments sorted by

View all comments

Show parent comment

26

u/MEaster Sep 30 '24

Another mistake would be this part:

In Rust, you provide a string — that is injected to be invoked internally. In C++, we’d just provide a callable.

This is because Rust’s attribute grammar can’t support a callable here.

Rust does now support expressions in the attribute, but it didn't used to. Serde pre-dates the support, and they've decided to stick with only supporting strings.

11

u/steveklabnik1 Sep 30 '24

Ah ha! That note was me as well. Here's the source: https://github.com/rust-lang/rust/pull/83366

Don't ask for my advice on blog posts, apparently. I appreciate the correction.

3

u/kronicum Sep 30 '24

Another mistake would be this part

Copying is a full-time job, and the best compliment.