[Question] Nightly type introspection instead of #[derive(HasField)] #217
Replies: 1 comment
-
|
Hi @jullanggit, sorry for the late reply. My understanding is that the compile-time reflection feature in Rust is more limited in scope, and is intended to serve different use cases than the features in CGP such as implicit arguments and getter traits. The main use case for compile-time reflection is to generate code for arbitrary data types. For example, for serializing or drawing arbitrary shape types. On the other hand, CGP features like implicit arguments and getter traits, work generically over any context type but require those contexts to have specific fields. These are fundamentally different problems, so the two features are largely complementary rather than competing. That said, compile-time reflection can indeed be used in place of some specific example use cases of CGP. For instance, cgp-serde already uses compile-time reflection-like capabilities via the trait system to access the same metadata at compile time, which illustrates how the two approaches can overlap in certain areas even as they diverge in others. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
There is ongoing work available in the nightly rust channel, which enables language-native type introspection. Do you think this (specifically the struct variant with its fields array) could at some point be used to remove the need for a #[derive(HasField)]? This isn't strictly necessary, as the derive works perfectly fine, but I'd be interested in hearing your opinion on this!
Beta Was this translation helpful? Give feedback.
All reactions