Skip to content

Commit

Permalink
refactor: Simplify the check for light_account attribute (#1219)
Browse files Browse the repository at this point in the history
Instead of a manual loop, use `.find()` and `.map()`.
  • Loading branch information
vadorovsky authored Sep 16, 2024
1 parent e499c4b commit 5586f7e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 20 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/light-examples-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@ on:
- main
paths:
- "examples/**"
- "macros/light-sdk-macros/**"
pull_request:
branches:
- "*"
paths:
- "examples/**"
- "macros/light-sdk-macros/**"
types:
- opened
- synchronize
Expand Down
29 changes: 9 additions & 20 deletions macros/light-sdk-macros/src/accounts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -345,26 +345,15 @@ pub(crate) fn process_light_accounts_derive(input: ItemStruct) -> Result<TokenSt
let field_ident = &field.ident;
field_idents.push(field_ident);

let mut account_args = None;
for attribute in &field.attrs {
let attribute_list = match &attribute.meta {
Meta::List(attribute_list) => attribute_list,
_ => continue,
};
account_args = Some(syn::parse2::<LightAccountArgs>(
attribute_list.tokens.clone(),
)?);
break;
}
let account_args = match account_args {
Some(account_args) => account_args,
None => {
return Err(Error::new_spanned(
input,
"no arguments provided in `light_account`",
))
}
};
let account_args = field
.attrs
.iter()
.find(|attribute| attribute.path().is_ident("light_account"))
.map(|attribute| attribute.parse_args::<LightAccountArgs>())
.transpose()?
.ok_or_else(|| {
Error::new_spanned(input.clone(), "no arguments provided in `light_account`")
})?;

let type_path = match field.ty {
Type::Path(ref type_path) => type_path,
Expand Down

0 comments on commit 5586f7e

Please sign in to comment.