• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //! Common functions
2 
3 use proc_macro2::Span;
4 use syn::{FieldsNamed, DataStruct, DeriveInput, Data, Fields, Error, Result};
5 
6 use crate::faultmsg::{StructIs, Problem};
7 
named_fields<'a>(structure: &'a DataStruct) -> Result<&'a FieldsNamed>8 pub fn named_fields<'a>(structure: &'a DataStruct) -> Result<&'a FieldsNamed> {
9     match structure.fields {
10         Fields::Named(ref fields) => Ok(fields),
11         Fields::Unnamed(_) | Fields::Unit => Err(
12             Error::new(Span::call_site(), Problem::UnnamedField)
13         ),
14     }
15 }
16 
named_struct<'a>(node: &'a DeriveInput) -> Result<&'a DataStruct>17 pub fn named_struct<'a>(node: &'a DeriveInput) -> Result<&'a DataStruct> {
18     match node.data {
19         Data::Struct(ref structure) => Ok(structure),
20         Data::Enum(_) => Err(
21             Error::new_spanned(node, Problem::NotNamedStruct(StructIs::Enum))
22         ),
23         Data::Union(_) => Err(
24             Error::new_spanned(node, Problem::NotNamedStruct(StructIs::Union))
25         ),
26     }
27 }
28