TedDriggs / darling

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

Support `with` on magic field `attrs` #273

Closed TedDriggs closed 8 months ago

TedDriggs commented 8 months ago

In colin-kiegel/rust-derive-builder#310, @dtolnay pointed out some clunky code that handles “distribution and unnesting” of attributes. The Options struct is forced to have an attrs field that is only temporarily used.

This can be avoided by allowing the deriver of FromDeriveInput et alia to provide a conversion function that takes attributes and returns a darling::Result<?>

This function must participate in the error accumulator behavior of the rest of the derived impl, so it must be invoked before the error check, and we’ll need a new local variable for the output.

with makes more sense than the postfix items, since this must allow failure and doesn’t itself take in a Result