1use super::metadata::{InnerVariantExt, InnerVariantMeta};
2use super::occurrence_error;
3use syn::{Field, LitStr};
4
5pub trait HasInnerVariantProperties {
6 fn get_variant_inner_properties(&self) -> syn::Result<StrumInnerVariantProperties>;
7}
8
9#[derive(Clone, Eq, PartialEq, Debug, Default)]
10pub struct StrumInnerVariantProperties {
11 pub default_with: Option<LitStr>,
12}
13
14impl HasInnerVariantProperties for Field {
15 fn get_variant_inner_properties(&self) -> syn::Result<StrumInnerVariantProperties> {
16 let mut output: StrumInnerVariantProperties = StrumInnerVariantProperties { default_with: None };
17
18 let mut default_with_kw: Option = None;
19 for meta: InnerVariantMeta in self.get_named_metadata()? {
20 match meta {
21 InnerVariantMeta::DefaultWith { kw: default_with, value: LitStr } => {
22 if let Some(fst_kw: default_with) = default_with_kw {
23 return Err(occurrence_error(fst_kw, snd:kw, attr:"default_with"));
24 }
25 default_with_kw = Some(kw);
26 output.default_with = Some(value);
27 }
28 }
29 }
30
31 Ok(output)
32 }
33}
34