• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 use super::metadata::{InnerVariantExt, InnerVariantMeta};
2 use super::occurrence_error;
3 use syn::{Field, LitStr};
4 
5 pub trait HasInnerVariantProperties {
get_variant_inner_properties(&self) -> syn::Result<StrumInnerVariantProperties>6     fn get_variant_inner_properties(&self) -> syn::Result<StrumInnerVariantProperties>;
7 }
8 
9 #[derive(Clone, Default)]
10 pub struct StrumInnerVariantProperties {
11     pub default_with: Option<LitStr>,
12 }
13 
14 impl HasInnerVariantProperties for Field {
get_variant_inner_properties(&self) -> syn::Result<StrumInnerVariantProperties>15     fn get_variant_inner_properties(&self) -> syn::Result<StrumInnerVariantProperties> {
16         let mut output = StrumInnerVariantProperties { default_with: None };
17 
18         let mut default_with_kw = None;
19         for meta in self.get_named_metadata()? {
20             match meta {
21                 InnerVariantMeta::DefaultWith { kw, value } => {
22                     if let Some(fst_kw) = default_with_kw {
23                         return Err(occurrence_error(fst_kw, kw, "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