ormlite_attr/
ext.rs

1use syn::{Data, DataStruct, DeriveInput, Field, Fields, FieldsNamed};
2
3pub trait DeriveInputExt {
4    fn fields(&self) -> syn::punctuated::Iter<'_, Field>;
5}
6
7impl DeriveInputExt for DeriveInput {
8    fn fields(&self) -> syn::punctuated::Iter<'_, Field> {
9        let fields = match &self.data {
10            Data::Struct(DataStruct { fields, .. }) => fields,
11            _ => panic!("#[ormlite] can only be used on structs"),
12        };
13        let fields = match fields {
14            Fields::Named(FieldsNamed { named, .. }) => named,
15            _ => panic!("#[ormlite] can only be used on structs with named fields"),
16        };
17        fields.iter()
18    }
19}