Well, if the only thing you need from reflection is the name of a type, so then yes. But I wouldn’t really call this reflection since it is very limited.
Yeah, Rust can’t have proper reflection, since there’s no external runtime environment that keeps track of your state. Any such smartness either has to be compiled-in (which is how std::any and macros work) or you can implement something to keep track of this state at runtime, as if you were partially building a runtime environment.
Here is a short summary. The compile-time reflection project was stopped, and now nobody wants to touch that subject any more due to fear of getting the wrath of the Rust project again (the person responsible for the whole thing is still part of the leadership).
And compile-time reflection will probably also continue to suck due to some irreconcilable limitations of type-safe generic specialization. Oh how I would love an equivalent to C++ template parameter packs…
So rust finally gets reflection? In stable no less!
Well, if the only thing you need from reflection is the name of a type, so then yes. But I wouldn’t really call this reflection since it is very limited.
Yeah, Rust can’t have proper reflection, since there’s no external runtime environment that keeps track of your state. Any such smartness either has to be compiled-in (which is how
std::any
and macros work) or you can implement something to keep track of this state at runtime, as if you were partially building a runtime environment.Minor point of clarification: it can’t have runtime reflection, but in principle it could have compile time reflection.
No, the Rust Project recently made sure that Rust can’t have compile-time reflection.
…yeah, that’s really unfortunate. Part of why I said “in principle”.
Can you expand on this? I’d love to read more on the subject.
Here is a short summary. The compile-time reflection project was stopped, and now nobody wants to touch that subject any more due to fear of getting the wrath of the Rust project again (the person responsible for the whole thing is still part of the leadership).
And compile-time reflection will probably also continue to suck due to some irreconcilable limitations of type-safe generic specialization. Oh how I would love an equivalent to C++ template parameter packs…
Unfortunately, it’s not guaranteed to be the same string all the time, so it’s rather useless for anything but debugging and logging.
@bwrsandman @snaggen More a RTTI than reflection…
Isn’t RTTI for polymorphic classes and stored in (or around) vtables?
@bwrsandman That’s why I used ”More a” than ”Is a”… 😉