Solid reflection in rust

This is pretty thoroughly covered in existing discussions, most recently Pre-RFC: Runtime reflection

IIRC the conclusions in that thread boiled down to "compile-time reflection is already mostly feasible with macro libraries, and there's no motivation for runtime reflection; the reasons Java/C#/etc have runtime reflection simply don't apply to Rust."

Perhaps most interesting was this post from an "enterprise" user of Rust who basically whipped up their own compile-time reflection stuff in-house and yet agrees for many reasons that it shouldn't be a core language feature:

In particular, the suggestions for improvement that post does make:

Things that, I think, would help us are smaller building blocks that we can use to create our "reflection" API, such as:

  • compile-time macroses for things like 1) field offsets 2) trait object vtables (yeah... there's a lot behind this "tiny" ask :slight_smile: )
  • maybe, some ABI stability for trait objects & such (so we can have types to be dynamically loadable)

are things actively being discussed by the community under other subject headers like "layout guarantees", since they're far more low-level than and would unlock a lot more use cases than just reflection code.

16 Likes