I have written a procedural macro that implements parsing a message specification from a byte stream for a struct by using helper attributes like so.
#[derive(MessageParsing)]
pub struct ExampleMessage {
#[scale = 0.0001]
field_1: u32,
#[bit_size = 12]
field_2: u16,
field_3_length: u8,
#[length_field = "field_3_length"]
#[fieldset(Field3 {
subfield_1: u16,
subfield_2: u16,
})]
field_3: Vec<Field3>
}
This properly expands to defining the Field3
struct and the auto-generated parsing logic for both ExampleMessage
and Field3
. The problem I encounter is when I try to use the other helper attributes in the definition for fieldset
like so
#[derive(MessageParsing)]
pub struct ExampleMessage {
#[scale = 0.0001]
field_1: u32,
#[bit_size = 12]
field_2: u16,
field_3_length: u8,
#[length_field = "field_3_length"]
#[fieldset(Field3 {
#[bit_size = 12]
subfield_1: u16,
#[scale = 0.01]
subfield_2: u16,
})]
field_3: Vec<Field3>
}
I get the error "cannot find attribute bit_size
in this scope. Is there a way to get the helper attributes recognized in the scope of the fieldset
attribute. I've tried creating a second pass-through macro with the same set of helper attributes defined and putting in #[derive(Passthrough)
before defining Field3
and it doesn't seem to make a difference. Is there some way of getting these attributes into the scope of the expression acting as an argument to fieldset
?