1use std::collections::BTreeSet;
2
3use crate::DynTapi;
4
5#[derive(Debug, Clone)]
6pub struct ContainerAttributes {
7 pub name: Name,
8 pub transparent: bool,
11 pub deny_unknown_fields: bool,
12 pub default: Default,
13 pub tag: TagType,
16 pub type_from: Option<DynTapi>,
17 pub type_try_from: Option<DynTapi>,
18 pub type_into: Option<DynTapi>,
19 pub is_packed: bool,
21 pub identifier: Identifier,
22 pub has_flatten: bool,
23 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#[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 default: Default,
150 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}