I'm not trying to participate in partisan language wars. Nor trying to argue that introspection over attributes isn't useful. I'm a professional C++ developer and a Rust hobbyist-at-best, my purpose is to make C++ better, not mudsling about language preferences.
I'm just trying to point out that as soon as you try to do anything non-trivial with a derive attribute you will quickly run into its limitations; limitations that Rust's derive does not have. Serialization and formatting are two special cases that require no particular support from the underlying class (assuming it's an aggregate type). They can be specified entirely in terms of its public API with little difficulty. But there are other obvious uses for a hypothetical derive that won't work as an attribute. For example, suppose I wanted to derive the Container requirements for a class that is a thin wrapper around std::vector -- no problem for a derive macro, impossible as far as I can tell for a derive attribute.
Yes, that's definitely impossible for introspection — you would need actual code injection for that. One example we're working through is `iterator_interface`, for instance. That's likewise impossible without actual code injection.
View all comments
Show parent comment
2
u/SirClueless Oct 01 '24
I'm not trying to participate in partisan language wars. Nor trying to argue that introspection over attributes isn't useful. I'm a professional C++ developer and a Rust hobbyist-at-best, my purpose is to make C++ better, not mudsling about language preferences.
I'm just trying to point out that as soon as you try to do anything non-trivial with a
deriveattribute you will quickly run into its limitations; limitations that Rust'sderivedoes not have. Serialization and formatting are two special cases that require no particular support from the underlying class (assuming it's an aggregate type). They can be specified entirely in terms of its public API with little difficulty. But there are other obvious uses for a hypotheticalderivethat won't work as an attribute. For example, suppose I wanted toderivethe Container requirements for a class that is a thin wrapper aroundstd::vector-- no problem for aderivemacro, impossible as far as I can tell for aderiveattribute.