tapi/
kind.rs

1use std::collections::BTreeSet;
2
3use crate::DynTapi;
4
5#[derive(Debug, Clone)]
6pub struct ContainerAttributes {
7    pub name: Name,
8    // pub rename_all_rules: RenameAllRules,
9    // pub rename_all_fields_rules: RenameAllRules,
10    pub transparent: bool,
11    pub deny_unknown_fields: bool,
12    pub default: Default,
13    // pub ser_bound: Option<Vec<WherePredicate>>,
14    // pub de_bound: Option<Vec<WherePredicate>>,
15    pub tag: TagType,
16    pub type_from: Option<DynTapi>,
17    pub type_try_from: Option<DynTapi>,
18    pub type_into: Option<DynTapi>,
19    // pub remote: Option<Path>,
20    pub is_packed: bool,
21    pub identifier: Identifier,
22    pub has_flatten: bool,
23    // pub custom_serde_path: Option<Path>,
24    // pub serde_path: Cow<'_, Path>,
25    // /// Error message generated when type can’t be deserialized. If None, default message will be used
26    // pub expecting: Option<String>,
27    pub non_exhaustive: bool,
28}
29
30#[derive(Debug, Clone)]
31pub struct Name {
32    pub serialize_name: String,
33    pub deserialize_name: String,
34}
35
36#[derive(Debug, Clone)]
37pub enum Default {
38    None,
39    Default,
40    Path,
41}
42
43#[derive(Debug, Clone)]
44pub enum TagType {
45    External,
46    Internal { tag: String },
47    Adjacent { tag: String, content: String },
48    None,
49}
50
51#[derive(Debug, Clone)]
52pub enum Identifier {
53    No,
54    Field,
55    Variant,
56}
57
58#[derive(Debug, Clone)]
59pub enum TypeKind {
60    Struct(Struct),
61    TupleStruct(TupleStruct),
62    Enum(Enum),
63    List(DynTapi),
64    Option(DynTapi),
65    Tuple(Vec<DynTapi>),
66    Builtin(BuiltinTypeKind),
67    Record(DynTapi, DynTapi),
68    Any,
69}
70
71#[derive(Debug, Clone)]
72pub enum BuiltinTypeKind {
73    U8,
74    U16,
75    U32,
76    U64,
77    U128,
78    I8,
79    I16,
80    I32,
81    I64,
82    I128,
83    F32,
84    F64,
85    Usize,
86    Isize,
87    Bool,
88    Char,
89    String,
90    Unit,
91}
92
93#[derive(Debug, Clone)]
94pub struct Struct {
95    pub attr: ContainerAttributes,
96    pub fields: Vec<Field>,
97}
98
99#[derive(Debug, Clone)]
100pub struct TupleStruct {
101    pub attr: ContainerAttributes,
102    pub fields: Vec<TupleStructField>,
103}
104
105#[derive(Debug, Clone)]
106pub struct TupleStructField {
107    pub attr: FieldAttributes,
108    pub ty: DynTapi,
109}
110
111#[derive(Debug, Clone)]
112pub struct Field {
113    pub attr: FieldAttributes,
114    pub name: FieldName,
115    pub ty: DynTapi,
116}
117
118#[derive(Clone)]
119pub enum FieldName {
120    Named(Name),
121    Index(usize),
122}
123
124impl std::fmt::Debug for FieldName {
125    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
126        match self {
127            FieldName::Named(name) => write!(f, "{:?}", name),
128            FieldName::Index(idx) => write!(f, "{:?}", idx),
129        }
130    }
131}
132
133// impl std::fmt::Display for FieldName {
134//     fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
135//         match self {
136//             FieldName::Named(name) => write!(f, "{}", name),
137//             FieldName::Index(idx) => write!(f, "{}", idx),
138//         }
139//     }
140// }
141
142#[derive(Debug, Clone)]
143pub struct FieldAttributes {
144    pub name: Name,
145    pub aliases: BTreeSet<String>,
146    pub skip_serializing: bool,
147    pub skip_deserializing: bool,
148    // pub skip_serializing_if: Option<ExprPath>,
149    pub default: Default,
150    // pub serialize_with: Option<ExprPath>,
151    // pub deserialize_with: Option<ExprPath>,
152    // pub ser_bound: Option<Vec<WherePredicate>>,
153    // pub de_bound: Option<Vec<WherePredicate>>,
154    // pub borrowed_lifetimes: BTreeSet<Lifetime>,
155    // pub getter: Option<ExprPath>,
156    pub flatten: bool,
157    pub transparent: bool,
158}
159
160#[derive(Debug, Clone)]
161pub struct Enum {
162    pub attr: ContainerAttributes,
163    pub variants: Vec<EnumVariant>,
164}
165
166#[derive(Debug, Clone)]
167pub struct EnumVariant {
168    pub name: String,
169    pub kind: VariantKind,
170}
171
172#[derive(Debug, Clone)]
173pub enum VariantKind {
174    Unit,
175    Tuple(Vec<DynTapi>),
176    Struct(Vec<Field>),
177}