Procedural macros

After spending a few days looking into macros in general I at least for the most part understand and am able to create both declarative and derivable macros. As for the other two that fall under procedural "category", that being function like and attribute macros I understand the very basics but not much past that. There's basically no documentation on either of the two unless I'm mistaken and I probably am. I've read the entirety of the official rust book about twice now and each time I read over the chapter that covers macros I get nothing from. It glazes over both. So basically all I'm asking for are some examples. Thank you in advance.

TLDR; what are some examples of attribute and function like macros?

I just recently added the jiff::tz::get! and jiff::tz::include! procedural macros to Jiff. You can see them defined here: jiff/crates/jiff-static/src/lib.rs at 0a0b5a0bee396aa99e736d76c24f77e2086daef5 · BurntSushi/jiff · GitHub

They're very simple. They just accept literal strings as input and generate a bunch of static-data to create time zones.

I feel like if you understand how to make derive macros, then you probably know enough to do function and attribute macros? Is there a specific place where you're getting hung up?

1 Like

Attribute macros are used in web server frameworks for defining endpoints, for example. See i.e. actix_web::get. Function-like macros can be helpful in cases where you want to parse your own syntax and transform that to Rust code, i.e. what web frontend frameworks like yew or dioxus do to implement their JSX-like functionality.

1 Like

Thank you both for your replies @jofas and @BurntSushi,I currently don't have time to fully look over the provided examples right now as I have class but will get to it later today. I am going to continue to leave this thread open most likely until this afternoon in the hopes more examples will be provided.