-
Notifications
You must be signed in to change notification settings - Fork 9
Open
Description
How to parse multiple attributes into a single struct? For example
// Library proc macro code
#[derive(bae::FromAttributes)]
struct Poise {
name: Option<syn::LitStr>,
placeholder: Option<syn::LitStr>,
min_length: Option<syn::LitInt>,
max_length: Option<syn::LitInt>,
}
// User code
struct MyModal {
#[poise(name = "First input label")]
#[poise(placeholder = "Your first input goes here")]
#[poise(min_length = 5)]
#[poise(min_length = 500)]
first_input: String,
}When parsing the field attributes with Poise::from_attributes(&field.attrs), only the first attributes is parsed:
Poise { name: Some(LitStr { token: "First input label" }), placeholder: None, min_length: None, max_length: None, paragraph: None }I assume this is because the parser code immediately returns upon encountering the first valid attribute:
Lines 165 to 173 in 3b018d1
| for attr in attrs { | |
| match attr.path.get_ident() { | |
| Some(ident) if ident == #attr_name => { | |
| return Some(syn::parse2::<Self>(attr.tokens.clone())).transpose() | |
| } | |
| // Ignore other attributes | |
| _ => {}, | |
| } | |
| } |
Would a PR for parsing all valid attributes be accepted?
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels