proc_macro_helper/
variant.rs1use attribute::Attribute;
2use field::Field;
3use syn;
4
5#[derive(Debug, Default, Eq, PartialEq, Clone)]
6pub struct Variant {
7 pub name: String,
8 pub fields: Vec<Field>,
9 pub attributes: Vec<Attribute>,
10}
11
12impl Variant {
13 pub fn parse(source: &::syn::Variant) -> Self {
14 let mut result = Variant::default();
15
16 result.name = source.ident.to_string();
17
18 result.attributes = source
19 .attrs
20 .iter()
21 .map(|x| x.interpret_meta().unwrap())
22 .map(|x| Attribute::parse(&x))
23 .collect();
24
25 result.fields = match source.fields {
26 syn::Fields::Unit => Vec::new(),
27 ::syn::Fields::Unnamed(ref x) => x.unnamed.iter().map(|x| Field::parse(x)).collect(),
28 ::syn::Fields::Named(ref x) => x.named.iter().map(|x| Field::parse(x)).collect(),
29 };
30
31 result
32 }
33}