> > Very flexible and powerful. (I even think this code could be released as > > a new public crate.) > > It's probably not _that_ useful in general, unless you're implementing > this kind of reflection... otherwise I would have found an existing > solution. :) But yes, it's very powerful.
Personally, I feel that projects that glue C and Rust together require similar tricks more, making them more challenging. > Out of curiosity, I asked claude.ai to explain it and it said "This is > a rather advanced use of Rust's type system and macro capabilities to > do compile-time reflection - basically inspecting the types of struct > fields without runtime overhead. While creative, this pattern isn't > commonly needed in everyday Rust code." > > When fed the initial comment from the Rust forum it said "your comment > about wanting to access <T as SomeTrait>::SOMETHING for a field's type > is a classic serialization pattern - often used to get things like > type IDs, serialization formats, or field metadata at compile time". > That's actually pretty impressive; the LLM was also impressed and it > started asking me more about it ("Are you building a custom > serialization framework from scratch, or extending an existing one?"). Incredible, commercial LLMs are so proficient in Rust and provide such professional comments (even a bit off-topic, it feels like LLMs could even review patches). Thank you for providing this interesting example. LLMs are indeed the good tool to help get started with and practice Rust. Thanks, Zhao