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
//! Family-of-records abstraction.
//!
//! [`RecordFamily`] is the trait every other workspace boundary
//! parameterises over once a consumer wants to index, observe, or
//! orchestrate a non-`dev.idiolect.*` record set. The hand-written
//! `dev.idiolect.*` family ([`AnyRecord`](crate::AnyRecord),
//! [`decode_record`](crate::decode_record), and friends) is the
//! generated `IdiolectFamily` shipped with this crate; downstream
//! consumers like `layers-pub` point `idiolect-codegen` at their own
//! lexicon set and get an isomorphic family back.
//!
//! # Composition
//!
//! Two families compose via [`OrFamily`] into a single family that
//! recognises every NSID either side claims. The compound's
//! [`AnyRecord`](RecordFamily::AnyRecord) is [`OrAny`], a tagged
//! union over the two halves. This is the dialect / curated-bundle
//! shape: a community curates a sub-family, and any consumer that
//! wants both can just use `OrFamily<F1, F2>`.
//!
//! Identical NSIDs claimed by both halves of an [`OrFamily`] are a
//! configuration error; [`OrFamily::decode`] resolves the left
//! family first, so the right family is shadowed in that case.
//! Detect overlaps via [`detect_or_family_overlap`] when wiring
//! production code paths.
use PhantomData;
use crateNsid;
use crateDecodeError;
/// A family is a discriminated set of record types: a membership
/// predicate over NSIDs, a decoder from JSON to a typed
/// [`AnyRecord`](Self::AnyRecord), and a serializer back.
///
/// Implementors are typically zero-sized marker types
/// (`pub struct IdiolectFamily;`); the trait's associated type and
/// const carry the family's whole identity, so the marker exists
/// only to dispatch through the trait system.
///
/// # Required methods
///
/// - [`contains`](Self::contains) — does this family carry a record
/// type at the given NSID?
/// - [`decode`](Self::decode) — turn a wire-form JSON body into the
/// corresponding `AnyRecord` variant. Returns `Ok(None)` for
/// out-of-family NSIDs so callers can chain through compound
/// families without an error variant.
/// - [`nsid_str`](Self::nsid_str) — the canonical NSID string of the
/// variant carried by an `AnyRecord`.
/// - [`to_typed_json`](Self::to_typed_json) — serialise an
/// `AnyRecord` back to wire form. Mirrors
/// [`AnyRecord::to_typed_json`](crate::AnyRecord::to_typed_json).
/// Tagged union over two record families.
///
/// Used as the `AnyRecord` of [`OrFamily<F1, F2>`]. `Left` carries
/// `F1::AnyRecord`, `Right` carries `F2::AnyRecord`. The variant
/// names track which side decoded the record, not any preference
/// ordering — both sides are equally first-class.
/// Compose two record families into a single family that recognises
/// every NSID either half claims.
///
/// Membership is the union of the two sides. Decoding tries the
/// left family first; on `Ok(None)` it tries the right. An NSID
/// claimed by both halves is shadowed by the left.
///
/// # Example
///
/// ```ignore
/// // pseudo-code; the real example would import generated families
/// type Combined = OrFamily<IdiolectFamily, LayersFamily>;
/// // drive_indexer::<Combined, _, _, _>(...)
/// ```
>);
/// Diagnostic helper: walk the NSIDs `F1` claims and report any that
/// `F2` also claims. Use at boot time when wiring an
/// [`OrFamily`] to catch configuration errors that would otherwise
/// only manifest as a silently-shadowed right-side decode.
///
/// Returns the empty vec when there is no overlap. Callers that want
/// strict semantics should `assert!(detect_or_family_overlap(...).is_empty())`.
///
/// The probe set is the caller's responsibility — pass the NSIDs
/// you care about (e.g. the union of [`F1::ID`](RecordFamily::ID)
/// and [`F2::ID`](RecordFamily::ID)-shaped probes, or a fixed
/// audit list).