TedDriggs / darling

A Rust proc-macro attribute parser
MIT License
1.02k stars 66 forks source link

[Question]: Procedural macros support structs with / without lifetime annotations #217

Closed dclong closed 1 year ago

dclong commented 1 year ago

Is there any example of using darling to develop procedural macros which support structs both with and without lifetime annotations?

TedDriggs commented 1 year ago

You can see how derive-builder handles generics (both type parameters and lifetimes) in its codegen here.

darling doesn't provide lifetime examples because those aren't really in this crate's area of focus: darling is focused on helping you turn an input AST into a useful representation for your own codegen. You can read generics using the generics magic field when deriving FromDeriveInput or the ty field when deriving FromField, both of which will give you access to lifetime information.

There is darling::usage::UsesLifetimes, which can be helpful if you allow users to tell your macro to ignore/skip fields from the DeriveInput, as it'll tell you which lifetimes are relevant to the output you're emitting.