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
use proc_macro2::Ident;
use syn::{DeriveInput, Field, FieldsNamed};

use crate::utils;

/// Odra event definition.
pub struct EventItem {
    struct_ident: Ident,
    named_fields: FieldsNamed
}

impl EventItem {
    pub fn parse(input: DeriveInput) -> Result<Self, syn::Error> {
        let struct_ident = input.ident.clone();
        let named_fields = utils::extract_fields(input)?;

        Ok(Self {
            struct_ident,
            named_fields
        })
    }

    pub fn fields_iter(&self) -> impl Iterator<Item = &Field> {
        self.named_fields.named.iter()
    }

    pub fn struct_ident(&self) -> &Ident {
        &self.struct_ident
    }
}