use proc_macro2::{Span, TokenStream};
use syn::Ident;
#[derive(Debug, Clone)]
pub struct Module {
pub ident: Ident,
pub generics: syn::Generics,
pub section: String,
pub fields: Vec<Field>,
}
#[derive(Debug, Clone)]
pub struct Field {
pub ident: Ident,
pub key: String,
pub kind: Option<FieldType>,
pub default: Option<TokenStream>,
pub init: Option<TokenStream>,
pub ignore: bool,
pub span: Span,
}
#[derive(Debug, Clone)]
pub struct FieldType {
pub container: ContainerKind,
pub scalar: ScalarKind,
}
#[derive(Debug, Clone, Copy)]
pub enum ContainerKind {
Plain,
Vec,
Option,
OptionVec,
}
#[derive(Debug, Clone)]
pub enum ScalarKind {
String,
Bool,
Integer(IntegerKind),
Float(FloatKind),
Datetime,
}
#[derive(Debug, Clone, Copy)]
pub enum IntegerKind {
I8,
I16,
I32,
I64,
Isize,
U8,
U16,
U32,
U64,
Usize,
}
#[derive(Debug, Clone, Copy)]
pub enum FloatKind {
F32,
F64,
}
impl IntegerKind {
pub fn type_tokens(&self) -> TokenStream {
match self {
Self::I8 => quote::quote!(i8),
Self::I16 => quote::quote!(i16),
Self::I32 => quote::quote!(i32),
Self::I64 => quote::quote!(i64),
Self::Isize => quote::quote!(isize),
Self::U8 => quote::quote!(u8),
Self::U16 => quote::quote!(u16),
Self::U32 => quote::quote!(u32),
Self::U64 => quote::quote!(u64),
Self::Usize => quote::quote!(usize),
}
}
}
impl FloatKind {
pub fn type_tokens(&self) -> TokenStream {
match self {
Self::F32 => quote::quote!(f32),
Self::F64 => quote::quote!(f64),
}
}
}