syn_utils/
attributes.rs

1use crate::*;
2
3pub fn filter_attributes(attrs: &[Attribute], allowed_idents: &[&str]) -> syn::Result<Vec<Meta>> {
4  let mut metas = Vec::new();
5
6  for attr in attrs {
7    let attr_ident = if let Some(ident) = attr.path().get_ident() {
8      ident.to_string()
9    } else {
10      continue;
11    };
12
13    if !allowed_idents.contains(&attr_ident.as_str()) {
14      continue;
15    }
16
17    let parser = |input: ParseStream| -> syn::Result<()> {
18      while !input.is_empty() {
19        let meta: Meta = input.parse()?;
20        metas.push(meta);
21
22        if input.is_empty() {
23          break;
24        }
25        let _: Token![,] = input.parse()?;
26      }
27      Ok(())
28    };
29
30    attr.parse_args_with(parser)?;
31  }
32
33  Ok(metas)
34}