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
//! Named verify-report types, shared by both faces.
//!
//! The first release shipped the embedded report as
//! `(Vec<(Vec<u8>, [u64; 6])>, [u64; 2])` — six unnamed counters per
//! index and two more for the spot check. The dogfood report's F10
//! ("two counters side by side with different time semantics and
//! nothing saying so") is the direct consequence: an anonymous array
//! has nowhere to write what a number means. These structs are where
//! that goes.
/// Per-index verification counters, one row of `TABLE.VERIFY`.
///
/// ```
/// let mut v = kevy_index::IndexVerify::new("t.at");
/// v.entries = 3;
/// assert_eq!((v.name.as_slice(), v.entries, v.drift), (&b"t.at"[..], 3, 0));
/// ```
/// The whole `TABLE.VERIFY` answer.
///
/// ```
/// let mut t = kevy_index::TableVerify::default();
/// t.per_index.push(kevy_index::IndexVerify::new("t.at"));
/// assert_eq!((t.per_index.len(), t.spot_rows), (1, 0));
/// ```
/// What `table_ensure` found (the boot verb — see the embedded docs).
///
/// The decision the boot verb makes, in terms of this crate:
///
/// ```
/// use kevy_index::{TableCatalog, TableEnsure, TableSpec, parse_table_declare, spec_diff};
///
/// fn ensure(cat: &mut TableCatalog, spec: TableSpec) -> Result<TableEnsure, String> {
/// match cat.get(&spec.name) {
/// None => {
/// cat.create(spec).map_err(|e| e.to_string())?;
/// Ok(TableEnsure::Created)
/// }
/// Some(cur) if cur.sans_auto() == spec => Ok(TableEnsure::Unchanged),
/// Some(cur) => Err(spec_diff(cur, &spec)),
/// }
/// }
///
/// let decl = |pk: &'static [u8]| {
/// parse_table_declare(&[b"TABLE.DECLARE", b"t", b"PREFIX", b"t:", b"PK", pk, b"COLUMN", pk, b"i64"])
/// };
/// let mut cat = TableCatalog::new();
/// assert_eq!(ensure(&mut cat, decl(b"id")?)?, TableEnsure::Created);
/// assert_eq!(ensure(&mut cat, decl(b"id")?)?, TableEnsure::Unchanged);
/// assert!(ensure(&mut cat, decl(b"uid")?).is_err());
/// # Ok::<(), Box<dyn std::error::Error>>(())
/// ```
/// Name the first difference between an admitted spec and a proposed
/// one — the message `table_ensure` refuses with. Specific enough to
/// act on, short enough for a boot log.
///
/// ```
/// use kevy_index::{parse_table_declare, spec_diff};
/// let cur = parse_table_declare(&[
/// b"TABLE.DECLARE", b"t", b"PREFIX", b"t:", b"PK", b"id", b"COLUMN", b"id", b"i64",
/// ])?;
/// let new = parse_table_declare(&[
/// b"TABLE.DECLARE", b"t", b"PREFIX", b"t2:", b"PK", b"id", b"COLUMN", b"id", b"i64",
/// ])?;
/// let msg = spec_diff(&cur, &new);
/// assert!(msg.starts_with("ERR table 't' exists with a different spec (PREFIX differ)"));
/// # Ok::<(), Box<dyn std::error::Error>>(())
/// ```