@@ -26,8 +26,13 @@ pub const SCHEMA_METADATA_KEY: &str = "avro.schema";
26
26
/// <https://avro.apache.org/docs/1.11.1/specification/#names>
27
27
#[ derive( Debug , Clone , PartialEq , Eq , Serialize , Deserialize ) ]
28
28
#[ serde( untagged) ]
29
+ /// A type name in an Avro schema
30
+ ///
31
+ /// This represents the different ways a type can be referenced in an Avro schema.
29
32
pub enum TypeName < ' a > {
33
+ /// A primitive type like null, boolean, int, etc.
30
34
Primitive ( PrimitiveType ) ,
35
+ /// A reference to another named type
31
36
Ref ( & ' a str ) ,
32
37
}
33
38
@@ -37,13 +42,21 @@ pub enum TypeName<'a> {
37
42
#[ derive( Debug , Clone , Copy , PartialEq , Eq , Serialize , Deserialize ) ]
38
43
#[ serde( rename_all = "camelCase" ) ]
39
44
pub enum PrimitiveType {
45
+ /// null: no value
40
46
Null ,
47
+ /// boolean: a binary value
41
48
Boolean ,
49
+ /// int: 32-bit signed integer
42
50
Int ,
51
+ /// long: 64-bit signed integer
43
52
Long ,
53
+ /// float: single precision (32-bit) IEEE 754 floating-point number
44
54
Float ,
55
+ /// double: double precision (64-bit) IEEE 754 floating-point number
45
56
Double ,
57
+ /// bytes: sequence of 8-bit unsigned bytes
46
58
Bytes ,
59
+ /// string: Unicode character sequence
47
60
String ,
48
61
}
49
62
@@ -78,22 +91,31 @@ impl Attributes<'_> {
78
91
#[ derive( Debug , Clone , PartialEq , Eq , Deserialize , Serialize ) ]
79
92
#[ serde( rename_all = "camelCase" ) ]
80
93
pub struct Type < ' a > {
94
+ /// The type of this Avro data structure
81
95
#[ serde( borrow) ]
82
96
pub r#type : TypeName < ' a > ,
97
+ /// Additional attributes associated with this type
83
98
#[ serde( flatten) ]
84
99
pub attributes : Attributes < ' a > ,
85
100
}
86
101
87
102
/// An Avro schema
103
+ ///
104
+ /// This represents the different shapes of Avro schemas as defined in the specification.
105
+ /// See <https://avro.apache.org/docs/1.11.1/specification/#schemas> for more details.
88
106
#[ derive( Debug , Clone , PartialEq , Eq , Serialize , Deserialize ) ]
89
107
#[ serde( untagged) ]
90
108
pub enum Schema < ' a > {
109
+ /// A direct type name (primitive or reference)
91
110
#[ serde( borrow) ]
92
111
TypeName ( TypeName < ' a > ) ,
112
+ /// A union of multiple schemas (e.g., ["null", "string"])
93
113
#[ serde( borrow) ]
94
114
Union ( Vec < Schema < ' a > > ) ,
115
+ /// A complex type such as record, array, map, etc.
95
116
#[ serde( borrow) ]
96
117
Complex ( ComplexType < ' a > ) ,
118
+ /// A type with attributes
97
119
#[ serde( borrow) ]
98
120
Type ( Type < ' a > ) ,
99
121
}
@@ -104,14 +126,19 @@ pub enum Schema<'a> {
104
126
#[ derive( Debug , Clone , PartialEq , Eq , Serialize , Deserialize ) ]
105
127
#[ serde( tag = "type" , rename_all = "camelCase" ) ]
106
128
pub enum ComplexType < ' a > {
129
+ /// Record type: a sequence of fields with names and types
107
130
#[ serde( borrow) ]
108
131
Record ( Record < ' a > ) ,
132
+ /// Enum type: a set of named values
109
133
#[ serde( borrow) ]
110
134
Enum ( Enum < ' a > ) ,
135
+ /// Array type: a sequence of values of the same type
111
136
#[ serde( borrow) ]
112
137
Array ( Array < ' a > ) ,
138
+ /// Map type: a mapping from strings to values of the same type
113
139
#[ serde( borrow) ]
114
140
Map ( Map < ' a > ) ,
141
+ /// Fixed type: a fixed-size byte array
115
142
#[ serde( borrow) ]
116
143
Fixed ( Fixed < ' a > ) ,
117
144
}
@@ -121,29 +148,39 @@ pub enum ComplexType<'a> {
121
148
/// <https://avro.apache.org/docs/1.11.1/specification/#schema-record>
122
149
#[ derive( Debug , Clone , PartialEq , Eq , Serialize , Deserialize ) ]
123
150
pub struct Record < ' a > {
151
+ /// Name of the record
124
152
#[ serde( borrow) ]
125
153
pub name : & ' a str ,
154
+ /// Optional namespace for the record, provides a way to organize names
126
155
#[ serde( borrow, default ) ]
127
156
pub namespace : Option < & ' a str > ,
157
+ /// Optional documentation string for the record
128
158
#[ serde( borrow, default ) ]
129
159
pub doc : Option < & ' a str > ,
160
+ /// Alternative names for this record
130
161
#[ serde( borrow, default ) ]
131
162
pub aliases : Vec < & ' a str > ,
163
+ /// The fields contained in this record
132
164
#[ serde( borrow) ]
133
165
pub fields : Vec < Field < ' a > > ,
166
+ /// Additional attributes for this record
134
167
#[ serde( flatten) ]
135
168
pub attributes : Attributes < ' a > ,
136
169
}
137
170
138
171
/// A field within a [`Record`]
139
172
#[ derive( Debug , Clone , PartialEq , Eq , Serialize , Deserialize ) ]
140
173
pub struct Field < ' a > {
174
+ /// Name of the field within the record
141
175
#[ serde( borrow) ]
142
176
pub name : & ' a str ,
177
+ /// Optional documentation for this field
143
178
#[ serde( borrow, default ) ]
144
179
pub doc : Option < & ' a str > ,
180
+ /// The field's type definition
145
181
#[ serde( borrow) ]
146
182
pub r#type : Schema < ' a > ,
183
+ /// Optional default value for this field
147
184
#[ serde( borrow, default ) ]
148
185
pub default : Option < & ' a str > ,
149
186
}
@@ -153,18 +190,25 @@ pub struct Field<'a> {
153
190
/// <https://avro.apache.org/docs/1.11.1/specification/#enums>
154
191
#[ derive( Debug , Clone , PartialEq , Eq , Serialize , Deserialize ) ]
155
192
pub struct Enum < ' a > {
193
+ /// Name of the enum
156
194
#[ serde( borrow) ]
157
195
pub name : & ' a str ,
196
+ /// Optional namespace for the enum, provides organizational structure
158
197
#[ serde( borrow, default ) ]
159
198
pub namespace : Option < & ' a str > ,
199
+ /// Optional documentation string describing the enum
160
200
#[ serde( borrow, default ) ]
161
201
pub doc : Option < & ' a str > ,
202
+ /// Alternative names for this enum
162
203
#[ serde( borrow, default ) ]
163
204
pub aliases : Vec < & ' a str > ,
205
+ /// The symbols (values) that this enum can have
164
206
#[ serde( borrow) ]
165
207
pub symbols : Vec < & ' a str > ,
208
+ /// Optional default value for this enum
166
209
#[ serde( borrow, default ) ]
167
210
pub default : Option < & ' a str > ,
211
+ /// Additional attributes for this enum
168
212
#[ serde( flatten) ]
169
213
pub attributes : Attributes < ' a > ,
170
214
}
@@ -174,8 +218,10 @@ pub struct Enum<'a> {
174
218
/// <https://avro.apache.org/docs/1.11.1/specification/#arrays>
175
219
#[ derive( Debug , Clone , PartialEq , Eq , Serialize , Deserialize ) ]
176
220
pub struct Array < ' a > {
221
+ /// The schema for items in this array
177
222
#[ serde( borrow) ]
178
223
pub items : Box < Schema < ' a > > ,
224
+ /// Additional attributes for this array
179
225
#[ serde( flatten) ]
180
226
pub attributes : Attributes < ' a > ,
181
227
}
@@ -185,8 +231,10 @@ pub struct Array<'a> {
185
231
/// <https://avro.apache.org/docs/1.11.1/specification/#maps>
186
232
#[ derive( Debug , Clone , PartialEq , Eq , Serialize , Deserialize ) ]
187
233
pub struct Map < ' a > {
234
+ /// The schema for values in this map
188
235
#[ serde( borrow) ]
189
236
pub values : Box < Schema < ' a > > ,
237
+ /// Additional attributes for this map
190
238
#[ serde( flatten) ]
191
239
pub attributes : Attributes < ' a > ,
192
240
}
@@ -196,13 +244,18 @@ pub struct Map<'a> {
196
244
/// <https://avro.apache.org/docs/1.11.1/specification/#fixed>
197
245
#[ derive( Debug , Clone , PartialEq , Eq , Serialize , Deserialize ) ]
198
246
pub struct Fixed < ' a > {
247
+ /// Name of the fixed type
199
248
#[ serde( borrow) ]
200
249
pub name : & ' a str ,
250
+ /// Optional namespace for the fixed type
201
251
#[ serde( borrow, default ) ]
202
252
pub namespace : Option < & ' a str > ,
253
+ /// Alternative names for this fixed type
203
254
#[ serde( borrow, default ) ]
204
255
pub aliases : Vec < & ' a str > ,
256
+ /// The number of bytes in this fixed type
205
257
pub size : usize ,
258
+ /// Additional attributes for this fixed type
206
259
#[ serde( flatten) ]
207
260
pub attributes : Attributes < ' a > ,
208
261
}
0 commit comments