TedDriggs / darling

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

Parsing "naked" attributes #246

Closed DCNick3 closed 1 year ago

DCNick3 commented 1 year ago

Is it possible to parse "naked" attributes, like the ones you can find in thiserror? They do not have a common attribute with fields inside them being the meaning (like in darling), but the mere presence of that attribute is what conveys the information.

enum Error {
    SomeCase(String),
    AnotherCase(#[source] AnotherError)
}

I would like a boolean flag in the received that would be false for the field of the first variant and true for the second one. Is it possible to achieve with darling?

TedDriggs commented 1 year ago

There is not natively; your best bet is to use the forward_attrs to collect all the ones you're interested in, and to then use and_then or map to take apart the attrs. derive_builder has some examples of this in its source code.