#Handle field attributes in attribute proc macro
3 messages · Page 1 of 1 (latest)
Currently I have a attribute proc macro like so:
#[foo(bar)]
MyStruct {
alpha: usize,
// ...
}
This generates another struct (which let's call MyStructFoo).
What I want, is something like what serde allows you to do:
#[foo(bar)]
MyStruct {
#[foo(baz)]
alpha: usize,
// ...
}
The generated MyStructFoo would be altered somewhat by this #[foo(baz)] field attribute.
I recognize that in the case of serde, it's a derive proc macro rather than an attribute proc macro, so it's slightly different. So the implementation would be somewhat different too (if possible at all).
Currently I'm just trying to read attributes on each Field, checking if it's foo, and if so do whatever I intend to do. But I'm getting this error:
error: expected non-macro attribute, found attribute macro
foo
Is this a namespace issue? I.e. the internal attribute foo has to be named different than the outer attribute foo?
Or do I need to declare another attribute proc macro for the internal foo attribute?