TedDriggs / darling

A Rust proc-macro attribute parser

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

dclong opened this issue · comments

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

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.