Live data from Hacker News

Practical Procedural Macros in Rust

xy2.dev

1–6 of 6 posts

Re: Practical Procedural Macros in Rust

#2
This is super useful! I'm trying to write my first real, quite involved proc_macro library (https://github.com/martijnarts/smooth_grahpql), and getting an overview of what all is and isn't possible and where to start has been a pain. It might be worth highlighting https://crates.io/crates/darling, also, I've found it very useful.

I'd especially been missing the testing bit! Thanks!

Re: Practical Procedural Macros in Rust

#3

This is super useful! I'm trying to write my first real, quite involved proc_macro library ( https://github.com/martijnarts/smooth_grahpql ), and getting an overview of what all is and isn't possible and where to start has been a pain. It might be worth highlighting https://crates.io/crates/darling , also, I've found it very useful. I'd especially been missing the testing bit! Thanks!

Thanks, glad you found it useful :)

Re: Practical Procedural Macros in Rust

#4
I would very much second the suggestion to do David Tolnay’s Proc Macro Workshop if you want to start understanding how to write them. I’d been writing Rust for years but always kind of avoided proc macros.

When I had a need for them, I went through only the first section of the workshop and everything clicked. You can just do the derive macro section and all the strange and scary-looking macro syntax will make sense. I realized that there is only a bit of extra syntax but it’s used very often so it can seem a little overwhelming when reading macro code.

https://github.com/dtolnay/proc-macro-workshop

Re: Practical Procedural Macros in Rust

#6

I would very much second the suggestion to do David Tolnay’s Proc Macro Workshop if you want to start understanding how to write them. I’d been writing Rust for years but always kind of avoided proc macros. When I had a need for them, I went through only the first section of the workshop and everything clicked. You can just do the derive macro section and all the strange and scary-looking macro syntax will make sense…

That repo is great. It really helped me get from zero to ... where ever I am now (non-zero I guess, I'm still early in my rust journey.) I do wish there was a 'completed' branch I could look at for reference though. Closest I found was this: https://docs.rs/modular-bitfield/latest/modular_bitfield/