dtolnay / proc-macro-workshop

Learn to write Rust procedural macros  [Rust Latam conference, Montevideo Uruguay, March 2019]
Apache License 2.0
4k stars 1.01k forks source link

Feature request: examples using proc-macro2 and darling #31

Closed ckaran closed 2 years ago

ckaran commented 4 years ago

Thank you for creating this project! It's what I've been looking for to learn how to write procedural macros in rust.

I noticed that you are the co-author of the proc-macro2 crate; could you add some examples of how to use that crate here? Also, could you give examples of how to use darling?

I know nothing about writing macros, but want to learn how to do so correctly so that end users actually want to use my macros, instead of feeling that they have to use them. So once again, thank you for making this project!

dmgolembiowski commented 3 years ago

@ckaran There are some nice demos of darling example usage on their repository. Also about 2 weeks ago, the proc-macro-2 repository updated its test suite. Looking at tests are a great way to potentially discover an alternative to explicitly labeled "examples". They also show you interesting tools for making tests for your own stuff.

ckaran commented 3 years ago

@dmgolembiowski Thank you for the suggestions, I'll look into them as well.

dtolnay commented 2 years ago

I am not a fan of the darling crate so I don't feel the need to cover it.

For proc-macro2 — I think this is already sufficiently covered by the workshop, especially the seq! project which involves directly working with tokens and not syntax trees.

ckaran commented 2 years ago

I am not a fan of the darling crate so I don't feel the need to cover it.

Can you please elaborate on why? I know so little about writing proc macros that any explanations of what I should be looking out for are always appreciated.