use std::collections::HashMap;
use std::fmt::{self, Display};
use syn::{Ident, Path};
#[derive(Debug, Clone)]
pub struct Container<'a> {
pub ident: syn::Ident,
pub attrs: HashMap<String, Val>,
pub data: Data<'a>,
pub generics: &'a syn::Generics,
pub original: &'a syn::DeriveInput,
}
#[derive(Debug, Clone)]
pub enum Data<'a> {
Enum(Vec<Variant<'a>>),
Struct(Style, Vec<Field<'a>>),
}
#[derive(Debug, Clone, Copy)]
pub enum Style {
Struct,
Tuple,
Newtype,
Unit,
}
#[derive(Debug, Clone)]
pub struct Variant<'a> {
pub ident: syn::Ident,
pub attrs: HashMap<String, Val>,
pub style: Style,
pub fields: Vec<Field<'a>>,
pub original: &'a syn::Variant,
}
#[derive(Debug, Clone)]
pub struct Field<'a> {
pub member: syn::Member,
pub attrs: HashMap<String, Val>,
pub ty: &'a syn::Type,
pub original: &'a syn::Field,
}
#[derive(Copy, Clone)]
pub struct Symbol(pub &'static str);
impl PartialEq<Symbol> for Ident {
fn eq(&self, word: &Symbol) -> bool {
self == word.0
}
}
impl<'a> PartialEq<Symbol> for &'a Ident {
fn eq(&self, word: &Symbol) -> bool {
*self == word.0
}
}
impl PartialEq<Symbol> for Path {
fn eq(&self, word: &Symbol) -> bool {
self.is_ident(word.0)
}
}
impl<'a> PartialEq<Symbol> for &'a Path {
fn eq(&self, word: &Symbol) -> bool {
self.is_ident(word.0)
}
}
impl Display for Symbol {
fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
formatter.write_str(self.0)
}
}
#[derive(Debug, Clone)]
pub enum Val {
Empty,
Str(String),
Map(HashMap<String, Val>),
}