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
use super::metadata::{InnerVariantExt, InnerVariantMeta};
use super::occurrence_error;
use syn::{Field, LitStr};

pub trait HasInnerVariantProperties {
    fn get_variant_inner_properties(&self) -> syn::Result<StrumInnerVariantProperties>;
}

#[derive(Clone, Eq, PartialEq, Debug, Default)]
pub struct StrumInnerVariantProperties {
    pub default_with: Option<LitStr>,
}

impl HasInnerVariantProperties for Field {
    fn get_variant_inner_properties(&self) -> syn::Result<StrumInnerVariantProperties> {
        let mut output = StrumInnerVariantProperties { default_with: None };

        let mut default_with_kw = None;
        for meta in self.get_named_metadata()? {
            match meta {
                InnerVariantMeta::DefaultWith { kw, value } => {
                    if let Some(fst_kw) = default_with_kw {
                        return Err(occurrence_error(fst_kw, kw, "default_with"));
                    }
                    default_with_kw = Some(kw);
                    output.default_with = Some(value);
                }
            }
        }

        Ok(output)
    }
}