Re:Deriving Traits in Rust with Procedural Macros
by redshirtrob on Thursday January 03, 2019 @11:40AM
(#18816414)
Agreed. I was anxiously waiting for proc macros to land on stable for quite a while and was very happy when they did.
But, when the time came to implement my custom derive I had to consult many sources. I ended up piecing together what I needed from a combination of:
- Official documentation (The Book)
- Blog posts
- Reading Serde code (And Syn/Proc-Macro/Proc-Macro2)
I also found the introduction of the proc-macro2 shim crate (however well intentioned) caused quite a bit of confusion. Specifically, it wasn't clean if I should use proc-macro or proc-macro2, and if I should be using the TokenStream exported by the former or the latter. Or should I be using one in some cases, and the other in some cases. Ditto for a few other things that I just can't recall right now.
I did get things put together eventually, but I don't feel I understand things well enough to explain to someone else...yet.
All that said, it's a hugely powerful feature and well worth the time if you need to do things that require intimate knowledge of the AST.
But, when the time came to implement my custom derive I had to consult many sources. I ended up piecing together what I needed from a combination of:
I also found the introduction of the proc-macro2 shim crate (however well intentioned) caused quite a bit of confusion. Specifically, it wasn't clean if I should use proc-macro or proc-macro2, and if I should be using the TokenStream exported by the former or the latter. Or should I be using one in some cases, and the other in some cases. Ditto for a few other things that I just can't recall right now.I did get things put together eventually, but I don't feel I understand things well enough to explain to someone else...yet.
All that said, it's a hugely powerful feature and well worth the time if you need to do things that require intimate knowledge of the AST.