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
//! The traits and constants that do not belong to any one format.
//!
//! A struct's *schema* is format independent: the same field list, in the same
//! order, under the same keys, whether it is going out as JSON text or BEVE
//! binary. That schema is [`Keys`], and the [`object!`](crate::object) macro
//! generates it once per type. A struct declared positionally has no keys to
//! share, only a length: that is [`Elements`], from [`array!`](crate::array).
//! An enum shares its variant names, which is [`Variants`], from
//! [`unit_enum!`](crate::unit_enum) and [`tagged_enum!`](crate::tagged_enum).
//!
//! Everything downstream of the schema is format specific and lives in
//! [`json`](crate::json) and [`beve`](crate::beve): each has its own `Read`,
//! `Write`, `ReadObject`, and `WriteObject`.
use PhantomData;
use crateKeyMap;
use crateOptions;
/// The key schema of a struct, and its compile-time perfect hash.
///
/// Shared by every format, because the keys are a property of the type rather
/// than of the encoding. JSON looks a key up out of a quoted run of document
/// bytes and BEVE out of a length-prefixed one, but both land in the same
/// table and yield the same field index.
/// The variant names of an enum, and their compile-time perfect hash.
///
/// The enum counterpart of [`Keys`], and shared by every format for the same
/// reason: which variants there are and what they are called is a property of
/// the type, not of the encoding. A name goes out as a JSON string or as a
/// BEVE one, but both land in the same table and yield the same variant index.
///
/// Generated by [`unit_enum!`](crate::unit_enum) and
/// [`tagged_enum!`](crate::tagged_enum).
/// The bookkeeping behind [`Options::ERROR_ON_MISSING_KEYS`] and
/// [`Keys::REQUIRED`], and the one place a struct too wide for the first is
/// refused.
///
/// An object reader sets bit `i` when it fills field `i`; an object that ends
/// holding anything less than [`MASK`](Fields::MASK) left a member out that
/// either the policy or the type insisted on.
pub >);
/// Convenience bound for generic containers: readable and writable in every
/// format this crate supports, from any input.
///
/// [`object!`](crate::object) generates impls for all formats at once, so a
/// generic struct's type parameter needs all of them. This is the bound to
/// write:
///
/// ```ignore
/// structio::object!([T: structio::ReadWrite] Page<T> { items, cursor });
/// ```
///
/// Types that borrow from the input do not satisfy this, exactly as they do
/// not satisfy an "owned" bound elsewhere in the ecosystem. For a struct that
/// is only ever used with one format, the narrower [`json::ReadWrite`] or
/// [`beve::ReadWrite`] will do.
///
/// [`json::ReadWrite`]: crate::json::ReadWrite
/// [`beve::ReadWrite`]: crate::beve::ReadWrite
/// The length of a struct encoded as a positional array.
///
/// The array counterpart of [`Keys`], and shared by every format for the same
/// reason: which fields there are and what order they come in is a property of
/// the type, not of the encoding. JSON writes them between brackets and BEVE
/// behind a generic-array header, but both write the same values in the same
/// order, and both refuse a document that holds a different number of them.
///
/// Generated by [`array!`](crate::array), which unlike [`object!`](crate::object)
/// emits no key list and no hash table: an element is found by counting, so
/// there is nothing to look up.
// A tuple is an array-encoded struct whose fields happen to have no names, so
// it reaches the same drivers through the same trait.
impl_tuple_elements!;
impl_tuple_elements!;
impl_tuple_elements!;
impl_tuple_elements!;
impl_tuple_elements!;
impl_tuple_elements!;
impl_tuple_elements!;
impl_tuple_elements!;
impl_tuple_elements!;
impl_tuple_elements!;
impl_tuple_elements!;
impl_tuple_elements!;
/// The identity adapter: read and write this position the way the type itself
/// would.
///
/// Adapters compose as types do, so a container adapter needs something to
/// name at a position that wants no adapting. `Vec<Same>` reads a `Vec<T>`
/// element for element as `Vec<T>`'s own impl does, and
/// `HashMap<Same, Millis>` adapts only a map's values, leaving its keys to
/// [`FromJsonKey`](crate::json::FromJsonKey) and
/// [`FromBeveKey`](crate::beve::FromBeveKey).
///
/// One type rather than one per format, because a declaration names a single
/// adapter and the macro emits it against [`json::ReadAs`](crate::json::ReadAs),
/// [`json::WriteAs`](crate::json::WriteAs),
/// [`beve::ReadAs`](crate::beve::ReadAs) and
/// [`beve::WriteAs`](crate::beve::WriteAs) alike. A per-format `Same` could
/// not be written at a field at all.
///
/// It is an identity on the bytes too, not only on the values, and in both
/// directions: `Same` forwards BEVE's
/// [`Write::ARRAY`](crate::beve::Write::ARRAY), so a `Vec<Same>` over a
/// `Vec<f64>` is still one typed array rather than a value per element, and it
/// forwards [`Read::read_bulk`](crate::beve::Read::read_bulk), so reading that
/// array back is still the single `memcpy` the unadapted field would have got.
///
/// Neither is true of an adapter in general, and neither should be. An adapter
/// with a conversion to do has no block to copy, so it leaves both alone and
/// gets a generic array and an element-by-element read. What `Same` shows is
/// that the ceiling is the adapter's, not the mechanism's: an adapter over a
/// type whose memory is already a payload can reach the same two paths, which
/// is what [`NumericBytes`](crate::beve::NumericBytes) is implementable for.
;
/// Refuse an internally tagged declaration whose tag is also a field of the
/// variant's payload.
///
/// The two share one object, so a collision writes the name twice:
/// `{"kind":"Config","kind":"debug"}`. This crate reads that back, taking the
/// first member as the tag, and a last-wins parser does not: it resolves the
/// name to the payload's value and the variant is gone. The field is
/// unreadable here as well, the tag having been consumed before the payload's
/// members are reached, so the configuration is dead in both directions rather
/// than merely unwise.
///
/// `ctor` is never called. A tuple variant's constructor is a value of type
/// `fn(P) -> E`, so naming it is what tells this function what `P` is: the
/// payload's type is deliberately absent from the declaration, and the
/// constructor is the one place the macro can reach it without asking for it
/// twice. `tag` is an ordinary argument rather than an associated constant
/// because the call sites are const contexts holding the literal, which is
/// what keeps this free of any trait the enum would have to implement.
///
/// [`tagged_enum!`](crate::tagged_enum) calls it, for a declaration carrying a
/// tag clause, from an item-level `const`, so with no generics it is evaluated
/// by `cargo check`. A generic one has no keys until it is instantiated, and
/// is checked from the write path's own `const` block instead, which is
/// [`Keys::REQUIRED`]'s tier: reported when the crate is built.
///
/// Comparing bytes rather than `==`, `str` equality not being callable in a
/// const context on this crate's minimum compiler.
pub const