1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
pub fn named_struct_fields_from_data(data: syn::Data) -> Vec<syn::Field> {
if let syn::Data::Struct(e) = data {
if let syn::Fields::Named(e) = e.fields {
e.named.into_iter().collect::<Vec<_>>()
} else {
panic!();
}
} else {
panic!();
}
}
pub fn filter_attributes_from_fields<'a>(fields: &'a Vec<syn::Field>, att_to_find: &'static str) -> Vec<&'a syn::Field> {
fields
.iter()
.filter(|f|
f.attrs
.iter()
.any(|att| filter_attributes(att, att_to_find)))
.collect()
}
pub fn filter_attributes(attr: &syn::Attribute, att_to_find: &str) -> bool {
attr
.path
.segments
.iter()
.any(|a| {
let y = a.ident.to_string();
let r = y.as_str();
r == att_to_find
})
}
#[cfg(test)]
mod test {
#[test]
fn test() {
}
}