Closed jonasbb closed 1 year ago
This is not supported today. It's come up in #96, but mostly in the context of improving errors for that situation.
The closest I've come to finding a solution is #186, which creates a new Meta
that is generic over the eventual right-hand side of the =
token, allowing there to be things besides syn::Lit
there. That said...
FromMeta
impls (possibly to the point of forcing people into using the derived impl, which I don't like)darling
in particular.Thanks for the response. I was mainly interested in what the status is. Overall, I don't think it is that important to support, but it might work a bit nicer with IDE autocompletion, although when I just tested it with rust-analyzer I didn't see anything so far. I will definitely wait and see what kind of syn
changes are upcoming and if they make this easier in the future.
Hi, I am wondering if it is possible to process attribute macro arguments if they do not follow the
syn::Meta
pattern. As part of https://github.com/jonasbb/serde_with/issues/533 I am currently evaluating if I can use non-string proc macro arguments. But I am stuck on how I can process the arguments of my proc macro attribute.The idea is to specify an attribute
#[serde_as(crate = ::s_with)]
. Here, the::s_with
is the non-string part. Theargs
of the proc macro only covers these tokenscrate = ::s_with
.The problem is now that none of the
From*
traits seem to cover this use case. With string arguments, i.e.,crate = "::s_with"
this follows the syntax of asyn::Meta
, or more specificAttributeArgs
. But this does not work with the non-string variant, since the right-hand side is not a literal value. Right now, I am not aware of any type available insyn
which covers such arbitrary shaped macro arguments, except just usingTokenStream
. But there is noFromTokenStream
trait to go with it indarling
.There are some unreleased changes in
syn
which affect the typesAttribute
andAttributeArgs
. This might make supporting non-string arguments easier in the future.I just want to know if you have a better idea how to support this. For now, the only way I see is creating an artificial
Attribute
with theargs
TokenStream
and usingFromAttributes
afterwards.