Skip to main content

tusks_lib/codegen/util/
attribute.rs

1use syn::Attribute;
2
3use crate::{TusksModule, models::{ExternalModule, Tusk, TusksParameters}};
4
5impl TusksParameters {
6    pub fn extract_attributes<'a>(&'a self, names: &[&str]) -> Vec<&'a Attribute> {
7        self
8            .pstruct
9            .attrs
10            .iter()
11            .filter(|attr| {
12                attr.path().get_ident()
13                    .map(|ident| names.contains(&ident.to_string().as_str()))
14                    .unwrap_or(false)
15            })
16            .collect()
17    }
18
19}
20
21impl Tusk {
22    pub fn extract_attributes<'a>(&'a self, names: &[&str]) -> Vec<&'a Attribute> {
23        self.func.attrs.iter().filter(|attr| {
24            attr.path().get_ident()
25                .map(|ident| names.contains(&ident.to_string().as_str()))
26                .unwrap_or(false)
27        }).collect()
28    }
29}
30
31impl ExternalModule {
32    pub fn extract_attributes<'a>(&'a self, names: &[&str]) -> Vec<&'a Attribute> {
33        self.item_use.attrs.iter().filter(|attr| {
34            attr.path().get_ident()
35                .map(|ident| names.contains(&ident.to_string().as_str()))
36                .unwrap_or(false)
37        }).collect()
38    }
39}
40
41impl TusksModule {
42    pub fn extract_attributes<'a>(&'a self, names: &[&str]) -> Vec<&'a Attribute> {
43        self.attrs.0.iter().filter(|attr| {
44            attr.path().get_ident()
45                .map(|ident| names.contains(&ident.to_string().as_str()))
46                .unwrap_or(false)
47        }).collect()
48    }
49}