1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
//! The BEVE half of the trait set.
//!
//! The shape mirrors [`json`](crate::json) exactly: [`Read`] and [`Write`] for
//! every supported type, [`ReadObject`] and [`WriteObject`] for a struct's
//! fields against the shared [`Keys`] schema, and [`ReadArray`] and
//! [`WriteArray`] for one written positionally instead. A type declared with
//! [`object!`](crate::object) or [`array!`](crate::array) gets both sets at
//! once. [`ReadEnum`] is the same idea against the [`Variants`] schema, from
//! [`tagged_enum!`](crate::tagged_enum).
//!
//! [`ReadAs`] and [`WriteAs`] are the same pair as [`Read`] and [`Write`],
//! moved off the type and onto an *adapter*, which is what lets a field keep a
//! type from a crate you do not own. [`ReadKeyAs`] and [`WriteKeyAs`] are the
//! same idea for a map's keys, which go through
//! [`FromBeveKey`](crate::beve::FromBeveKey) rather than through [`Read`].
//!
//! The one thing BEVE adds is [`Write::ARRAY`]. JSON has a single array syntax,
//! so a sequence never has to ask what its elements are. BEVE stores a run of
//! numbers as a contiguous block with one header for the lot, which is most of
//! why it is worth having, so a sequence does have to ask. A run of
//! [`Complex`](crate::Complex) answers the same way, through the complex
//! extension.
use crate;
use crateWriter;
use cratePResult;
use crateOptions;
use crate;
/// A type that can be parsed from BEVE.
///
/// Reading is into an existing value, so buffers already held by the
/// destination get reused, exactly as on the JSON side.
///
/// The `'de` lifetime is the input buffer's. BEVE strings carry no escapes, so
/// a `&'de str` field always borrows and never has to fall back to a copy.
/// A type that can be serialized to BEVE.
///
/// The method is generic over the [write policy](crate::Options) rather than
/// the trait being generic over it, so a bound on a container element stays
/// `T: Write` instead of `T: Write<O>`.
/// How a field of type `T` is read when its declaration names this adapter.
///
/// The BEVE half of [`json::ReadAs`](crate::json::ReadAs), and the same idea:
/// the impl is on the adapter rather than on `T`, so a type from another crate
/// can be described without a newtype around it. A declaration names one
/// adapter for both formats, so an adapter used from [`object!`](crate::object)
/// needs this impl as well as the JSON one; one used from
/// [`beve_object!`](crate::beve_object) needs only this.
/// How a field of type `T` is written when its declaration names this adapter.
/// How a map key of type `T` is read when its declaration names this adapter.
///
/// A key is not a value: it goes through
/// [`FromBeveKey`](crate::beve::FromBeveKey) rather than through [`Read`], so
/// a key position takes its own adapter trait.
/// How a map key of type `T` is written when its declaration names this
/// adapter.
/// Field-by-field reading for a struct.
/// Field-by-field writing for a struct.
/// Element-by-element reading for a struct written as a BEVE array.
///
/// The positional counterpart of [`ReadObject`]. Any array form is accepted,
/// generic or typed, because the driver hands out one value per element either
/// way: a struct of three `f64`s reads back from the contiguous block another
/// implementation would have written for a `[f64; 3]`.
/// Element-by-element writing for a struct written as a BEVE array.
/// Variant-by-variant reading for an enum.
///
/// The counterpart of [`ReadObject`] for a type declared with
/// [`unit_enum!`](crate::unit_enum) or [`tagged_enum!`](crate::tagged_enum),
/// and the mirror of [`json::ReadEnum`](crate::json::ReadEnum). The wire forms
/// are the same two: a variant carrying nothing is a string, and a variant
/// carrying a value is an object of one member keyed by the name.
///
/// The name arrives already delimited, by its length prefix, so unlike the
/// JSON side there is nothing to walk to a closing quote. `index` is still
/// only the candidate the hash proposed, so both methods must confirm `name`
/// against their own before doing anything else.
/// Convenience bound for generic containers: readable from any BEVE input, and
/// writable.
///
/// Prefer [`crate::ReadWrite`], which also covers JSON, unless the type is
/// deliberately BEVE only.