caixa_theme/style.rs
1//! The small semantic-style enum every caixa tool agrees on.
2
3use serde::{Deserialize, Serialize};
4
5/// Substrate-canonical `"keyword"` lowercase kebab-case wire-form tag
6/// for [`Semantic::Keyword`] — the one canonical byte-string the paired
7/// forward emitter [`Semantic::as_str`], the paired reverse parser
8/// [`Semantic::from_wire`], and the paired exhaustive-roster
9/// [`Semantic::WIRE_NAMES`] axis all route through, so a future rebrand
10/// of the tag (a per-arm slug tightening on a future
11/// `feira lint --list-styles` operator-facing enumeration verb, a
12/// per-`SemanticTokenType` `caixa-lsp` re-mapping the LSP spec grows,
13/// a `blackmatter-shell` `data-semantic="<kebab>"` DOM-attribute
14/// re-convention) reaches every one of the sibling substrate-primitive
15/// dispatches through a single caixa-theme edit here — not an
16/// open-coded three-site parallel-maintained inline byte-string. Peer
17/// of the fifteen other `CAIXA_THEME_SEMANTIC_WIRE_*` const family
18/// entries on the sixteen-arm caixa-theme semantic-style
19/// canonical-lowercase-kebab wire-form axis.
20///
21/// Same closed-set lifted-const discipline the paired caixa-lint
22/// diagnostic-severity axis' [`CAIXA_LINT_SEVERITY_WIRE_*`] (a199462) /
23/// caixa-lint fix-safety-tier axis' [`CAIXA_LINT_FIX_SAFETY_WIRE_*`]
24/// (5837236) / caixa-arch invariant-kind axis'
25/// `CAIXA_ARCH_INVARIANT_KIND_WIRE_*` (78f5522) / caixa-arch verdict-
26/// outcome axis' `CAIXA_ARCH_VERDICT_WIRE_*` (ebddef0) const families
27/// carry — extends the paired substrate-primitive wire-form lift onto
28/// the fifth outside-caixa-core closed-set fieldless typed enum on the
29/// caixa surface (the caixa-theme semantic-style axis, and the first
30/// inside `caixa-theme`).
31///
32/// Pinned load-bearing at the substrate-primitive level by
33/// [`tests::semantic_wire_names_covers_every_arm`] (paired roster
34/// coverage pin closing this const family into
35/// [`Semantic::WIRE_NAMES`]).
36pub const CAIXA_THEME_SEMANTIC_WIRE_KEYWORD: &str = "keyword";
37
38/// Substrate-canonical `"symbol"` lowercase kebab-case wire-form tag
39/// for [`Semantic::Symbol`] — peer of the fifteen other
40/// `CAIXA_THEME_SEMANTIC_WIRE_*` const family entries on the sixteen-
41/// arm caixa-theme semantic-style canonical-lowercase-kebab wire-form
42/// axis. See [`CAIXA_THEME_SEMANTIC_WIRE_KEYWORD`] for the full lift
43/// rationale.
44pub const CAIXA_THEME_SEMANTIC_WIRE_SYMBOL: &str = "symbol";
45
46/// Substrate-canonical `"keyword-arg"` lowercase kebab-case wire-form
47/// tag for [`Semantic::KeywordArg`] — peer of the fifteen other
48/// `CAIXA_THEME_SEMANTIC_WIRE_*` const family entries on the sixteen-
49/// arm caixa-theme semantic-style canonical-lowercase-kebab wire-form
50/// axis. See [`CAIXA_THEME_SEMANTIC_WIRE_KEYWORD`] for the full lift
51/// rationale.
52pub const CAIXA_THEME_SEMANTIC_WIRE_KEYWORD_ARG: &str = "keyword-arg";
53
54/// Substrate-canonical `"string"` lowercase kebab-case wire-form tag
55/// for [`Semantic::String`] — peer of the fifteen other
56/// `CAIXA_THEME_SEMANTIC_WIRE_*` const family entries on the sixteen-
57/// arm caixa-theme semantic-style canonical-lowercase-kebab wire-form
58/// axis. See [`CAIXA_THEME_SEMANTIC_WIRE_KEYWORD`] for the full lift
59/// rationale.
60pub const CAIXA_THEME_SEMANTIC_WIRE_STRING: &str = "string";
61
62/// Substrate-canonical `"number"` lowercase kebab-case wire-form tag
63/// for [`Semantic::Number`] — peer of the fifteen other
64/// `CAIXA_THEME_SEMANTIC_WIRE_*` const family entries on the sixteen-
65/// arm caixa-theme semantic-style canonical-lowercase-kebab wire-form
66/// axis. See [`CAIXA_THEME_SEMANTIC_WIRE_KEYWORD`] for the full lift
67/// rationale.
68pub const CAIXA_THEME_SEMANTIC_WIRE_NUMBER: &str = "number";
69
70/// Substrate-canonical `"literal"` lowercase kebab-case wire-form tag
71/// for [`Semantic::Literal`] — peer of the fifteen other
72/// `CAIXA_THEME_SEMANTIC_WIRE_*` const family entries on the sixteen-
73/// arm caixa-theme semantic-style canonical-lowercase-kebab wire-form
74/// axis. See [`CAIXA_THEME_SEMANTIC_WIRE_KEYWORD`] for the full lift
75/// rationale.
76pub const CAIXA_THEME_SEMANTIC_WIRE_LITERAL: &str = "literal";
77
78/// Substrate-canonical `"comment"` lowercase kebab-case wire-form tag
79/// for [`Semantic::Comment`] — peer of the fifteen other
80/// `CAIXA_THEME_SEMANTIC_WIRE_*` const family entries on the sixteen-
81/// arm caixa-theme semantic-style canonical-lowercase-kebab wire-form
82/// axis. See [`CAIXA_THEME_SEMANTIC_WIRE_KEYWORD`] for the full lift
83/// rationale.
84pub const CAIXA_THEME_SEMANTIC_WIRE_COMMENT: &str = "comment";
85
86/// Substrate-canonical `"accent"` lowercase kebab-case wire-form tag
87/// for [`Semantic::Accent`] — peer of the fifteen other
88/// `CAIXA_THEME_SEMANTIC_WIRE_*` const family entries on the sixteen-
89/// arm caixa-theme semantic-style canonical-lowercase-kebab wire-form
90/// axis. See [`CAIXA_THEME_SEMANTIC_WIRE_KEYWORD`] for the full lift
91/// rationale.
92pub const CAIXA_THEME_SEMANTIC_WIRE_ACCENT: &str = "accent";
93
94/// Substrate-canonical `"muted"` lowercase kebab-case wire-form tag for
95/// [`Semantic::Muted`] — peer of the fifteen other
96/// `CAIXA_THEME_SEMANTIC_WIRE_*` const family entries on the sixteen-
97/// arm caixa-theme semantic-style canonical-lowercase-kebab wire-form
98/// axis. See [`CAIXA_THEME_SEMANTIC_WIRE_KEYWORD`] for the full lift
99/// rationale.
100pub const CAIXA_THEME_SEMANTIC_WIRE_MUTED: &str = "muted";
101
102/// Substrate-canonical `"error"` lowercase kebab-case wire-form tag for
103/// [`Semantic::Error`] — peer of the fifteen other
104/// `CAIXA_THEME_SEMANTIC_WIRE_*` const family entries on the sixteen-
105/// arm caixa-theme semantic-style canonical-lowercase-kebab wire-form
106/// axis. See [`CAIXA_THEME_SEMANTIC_WIRE_KEYWORD`] for the full lift
107/// rationale.
108pub const CAIXA_THEME_SEMANTIC_WIRE_ERROR: &str = "error";
109
110/// Substrate-canonical `"warning"` lowercase kebab-case wire-form tag
111/// for [`Semantic::Warning`] — peer of the fifteen other
112/// `CAIXA_THEME_SEMANTIC_WIRE_*` const family entries on the sixteen-
113/// arm caixa-theme semantic-style canonical-lowercase-kebab wire-form
114/// axis. See [`CAIXA_THEME_SEMANTIC_WIRE_KEYWORD`] for the full lift
115/// rationale.
116pub const CAIXA_THEME_SEMANTIC_WIRE_WARNING: &str = "warning";
117
118/// Substrate-canonical `"info"` lowercase kebab-case wire-form tag for
119/// [`Semantic::Info`] — peer of the fifteen other
120/// `CAIXA_THEME_SEMANTIC_WIRE_*` const family entries on the sixteen-
121/// arm caixa-theme semantic-style canonical-lowercase-kebab wire-form
122/// axis. See [`CAIXA_THEME_SEMANTIC_WIRE_KEYWORD`] for the full lift
123/// rationale.
124pub const CAIXA_THEME_SEMANTIC_WIRE_INFO: &str = "info";
125
126/// Substrate-canonical `"hint"` lowercase kebab-case wire-form tag for
127/// [`Semantic::Hint`] — peer of the fifteen other
128/// `CAIXA_THEME_SEMANTIC_WIRE_*` const family entries on the sixteen-
129/// arm caixa-theme semantic-style canonical-lowercase-kebab wire-form
130/// axis. See [`CAIXA_THEME_SEMANTIC_WIRE_KEYWORD`] for the full lift
131/// rationale.
132pub const CAIXA_THEME_SEMANTIC_WIRE_HINT: &str = "hint";
133
134/// Substrate-canonical `"added"` lowercase kebab-case wire-form tag for
135/// [`Semantic::Added`] — peer of the fifteen other
136/// `CAIXA_THEME_SEMANTIC_WIRE_*` const family entries on the sixteen-
137/// arm caixa-theme semantic-style canonical-lowercase-kebab wire-form
138/// axis. See [`CAIXA_THEME_SEMANTIC_WIRE_KEYWORD`] for the full lift
139/// rationale.
140pub const CAIXA_THEME_SEMANTIC_WIRE_ADDED: &str = "added";
141
142/// Substrate-canonical `"removed"` lowercase kebab-case wire-form tag
143/// for [`Semantic::Removed`] — peer of the fifteen other
144/// `CAIXA_THEME_SEMANTIC_WIRE_*` const family entries on the sixteen-
145/// arm caixa-theme semantic-style canonical-lowercase-kebab wire-form
146/// axis. See [`CAIXA_THEME_SEMANTIC_WIRE_KEYWORD`] for the full lift
147/// rationale.
148pub const CAIXA_THEME_SEMANTIC_WIRE_REMOVED: &str = "removed";
149
150/// Substrate-canonical `"unchanged"` lowercase kebab-case wire-form tag
151/// for [`Semantic::Unchanged`] — peer of the fifteen other
152/// `CAIXA_THEME_SEMANTIC_WIRE_*` const family entries on the sixteen-
153/// arm caixa-theme semantic-style canonical-lowercase-kebab wire-form
154/// axis. See [`CAIXA_THEME_SEMANTIC_WIRE_KEYWORD`] for the full lift
155/// rationale.
156pub const CAIXA_THEME_SEMANTIC_WIRE_UNCHANGED: &str = "unchanged";
157
158#[derive(
159 Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize, gen_platform::IsVariant,
160)]
161pub enum Semantic {
162 /// Language keywords — `defcaixa`, `defteia`, `let`, `lambda`, etc.
163 Keyword,
164 /// Non-keyword symbols — identifiers, function names, variant names.
165 Symbol,
166 /// `:keyword-positioned` atoms.
167 KeywordArg,
168 /// `"string literals"`.
169 String,
170 /// `42`, `3.14`.
171 Number,
172 /// `#t`, `#f`, `nil`.
173 Literal,
174 /// `; comments`.
175 Comment,
176 /// Primary accent — useful for highlights, carets, focused tokens.
177 Accent,
178 /// Dim text — metadata, line numbers, help text.
179 Muted,
180
181 // Diagnostic severities.
182 Error,
183 Warning,
184 Info,
185 Hint,
186
187 // Diff decorations — used by formatter preview and lint output.
188 Added,
189 Removed,
190 Unchanged,
191}
192
193impl Semantic {
194 /// Every variant of [`Semantic`] in declaration order.
195 ///
196 /// The single canonical arm-list every substrate consumer that has
197 /// to walk the closed 15-arm semantic-style partition (the two
198 /// theme overlays' exhaustive-match resolver functions
199 /// `blackmatter_dark_color` / `blackmatter_light_color` in
200 /// [`crate::blackmatter`], the future LSP-side per-Semantic
201 /// `SemanticTokenType` dispatch at
202 /// `caixa-lsp/src/main.rs`, a future
203 /// `feira lint --list-styles` operator-facing enumeration verb)
204 /// reads for. Peer of the sibling closed-set fieldless typed
205 /// enums' `ALL` slices already carried by
206 /// [`caixa_core::CaixaKind`] /
207 /// [`caixa_core::supervisor::RestartStrategy`] /
208 /// [`caixa_core::supervisor::RestartPolicy`] /
209 /// [`caixa_core::aplicacao::PlacementStrategy`] /
210 /// [`caixa_core::upgrade::UpgradeInstruction`] /
211 /// `caixa_lint::diagnostic::Severity` /
212 /// `caixa_lint::diagnostic::FixSafety` /
213 /// `caixa_arch::InvariantKind` / `caixa_arch::ArchVerdict` /
214 /// `caixa_provedor::FerriteRuntime` closed-set typed-enum
215 /// discriminator axes.
216 pub const ALL: &'static [Self] = &[
217 Self::Keyword,
218 Self::Symbol,
219 Self::KeywordArg,
220 Self::String,
221 Self::Number,
222 Self::Literal,
223 Self::Comment,
224 Self::Accent,
225 Self::Muted,
226 Self::Error,
227 Self::Warning,
228 Self::Info,
229 Self::Hint,
230 Self::Added,
231 Self::Removed,
232 Self::Unchanged,
233 ];
234
235 /// Exhaustive accept-set roster on the [`Semantic`] closed-set
236 /// enum's canonical-lowercase-kebab wire-form axis — the single
237 /// slice every consumer that enumerates the accepted semantic-style
238 /// byte-strings dispatches through (a future
239 /// `feira lint --list-styles` operator-facing enumeration verb
240 /// rendering the accepted-tag list, a future `caixa-lsp`-side
241 /// per-`SemanticTokenType` registration walk that enumerates every
242 /// accepted per-arm kebab byte-string on startup, a future
243 /// `caixa.nvim` per-highlight-group re-loader binding every
244 /// accepted kebab identifier back to the typed enum, a future
245 /// `blackmatter-shell` per-arm `data-semantic="<kebab>"`
246 /// DOM-attribute emission walk, a `tracing::field::valuable::Value::List`
247 /// structured-log accepted-style emit on the paint-side emission
248 /// path). Routed byte-for-byte through the paired
249 /// [`CAIXA_THEME_SEMANTIC_WIRE_KEYWORD`] /
250 /// [`CAIXA_THEME_SEMANTIC_WIRE_SYMBOL`] /
251 /// [`CAIXA_THEME_SEMANTIC_WIRE_KEYWORD_ARG`] /
252 /// [`CAIXA_THEME_SEMANTIC_WIRE_STRING`] /
253 /// [`CAIXA_THEME_SEMANTIC_WIRE_NUMBER`] /
254 /// [`CAIXA_THEME_SEMANTIC_WIRE_LITERAL`] /
255 /// [`CAIXA_THEME_SEMANTIC_WIRE_COMMENT`] /
256 /// [`CAIXA_THEME_SEMANTIC_WIRE_ACCENT`] /
257 /// [`CAIXA_THEME_SEMANTIC_WIRE_MUTED`] /
258 /// [`CAIXA_THEME_SEMANTIC_WIRE_ERROR`] /
259 /// [`CAIXA_THEME_SEMANTIC_WIRE_WARNING`] /
260 /// [`CAIXA_THEME_SEMANTIC_WIRE_INFO`] /
261 /// [`CAIXA_THEME_SEMANTIC_WIRE_HINT`] /
262 /// [`CAIXA_THEME_SEMANTIC_WIRE_ADDED`] /
263 /// [`CAIXA_THEME_SEMANTIC_WIRE_REMOVED`] /
264 /// [`CAIXA_THEME_SEMANTIC_WIRE_UNCHANGED`] lifted `pub const`
265 /// scalars in variant declaration order so a future arm rebrand
266 /// touches one const rather than an open-coded sixteen-site
267 /// parallel-maintained array literal.
268 ///
269 /// Peer of the sibling closed-set typed enums'
270 /// [`caixa_core::CaixaKind::WIRE_NAMES`] (bd708bd),
271 /// [`caixa_core::supervisor::RestartStrategy::WIRE_NAMES`] (3033f45),
272 /// [`caixa_core::supervisor::RestartPolicy::WIRE_NAMES`] (ce9412b),
273 /// [`caixa_core::aplicacao::PlacementStrategy::WIRE_NAMES`] (3e5b194),
274 /// [`caixa_core::render::PathShapeViolation::WIRE_NAMES`] (0330bd3),
275 /// [`caixa_core::CaixaDialeto::WIRE_NAMES`] (0402726),
276 /// `caixa_arch::invariants::InvariantKind::WIRE_NAMES` (78f5522),
277 /// `caixa_arch::report::ArchVerdict::WIRE_NAMES` (ebddef0),
278 /// `caixa_lint::diagnostic::Severity::WIRE_NAMES` (a199462), and
279 /// `caixa_lint::diagnostic::FixSafety::WIRE_NAMES` (5837236)
280 /// rosters — extends the paired exhaustive-roster axis onto the
281 /// *fifth outside*-caixa-core closed-set fieldless typed enum on
282 /// the caixa surface (the caixa-theme semantic-style axis, and the
283 /// first inside `caixa-theme`), with `caixa_provedor::FerriteRuntime`
284 /// remaining as the only outside-caixa-core closed-set fieldless
285 /// typed enum whose paired exhaustive-roster axis is still open.
286 ///
287 /// A future variant addition (a `Namespace` tier between
288 /// [`Self::Symbol`] and [`Self::KeywordArg`] for the M4 tatara-lisp
289 /// module system's qualified-name semantic-token dispatch, a
290 /// `Deleted` tier for a hard-delete-mark distinct from
291 /// [`Self::Removed`] the future 3-way diff surface grows — both
292 /// trajectory items the sibling [`Self::ALL`] doc block already
293 /// names) extends this roster as a single edit — the compiler-
294 /// checked exhaustiveness on [`Self::as_str`]'s match and the
295 /// paired [`tests::semantic_wire_names_covers_every_arm`] pin's
296 /// length / membership / order / round-trip gates keep the roster,
297 /// the emitter [`Self::as_str`], and the parser [`Self::from_wire`]
298 /// in structural lockstep by construction.
299 ///
300 /// Pinned load-bearing by
301 /// [`tests::semantic_wire_names_covers_every_arm`].
302 pub const WIRE_NAMES: &'static [&'static str] = &[
303 CAIXA_THEME_SEMANTIC_WIRE_KEYWORD,
304 CAIXA_THEME_SEMANTIC_WIRE_SYMBOL,
305 CAIXA_THEME_SEMANTIC_WIRE_KEYWORD_ARG,
306 CAIXA_THEME_SEMANTIC_WIRE_STRING,
307 CAIXA_THEME_SEMANTIC_WIRE_NUMBER,
308 CAIXA_THEME_SEMANTIC_WIRE_LITERAL,
309 CAIXA_THEME_SEMANTIC_WIRE_COMMENT,
310 CAIXA_THEME_SEMANTIC_WIRE_ACCENT,
311 CAIXA_THEME_SEMANTIC_WIRE_MUTED,
312 CAIXA_THEME_SEMANTIC_WIRE_ERROR,
313 CAIXA_THEME_SEMANTIC_WIRE_WARNING,
314 CAIXA_THEME_SEMANTIC_WIRE_INFO,
315 CAIXA_THEME_SEMANTIC_WIRE_HINT,
316 CAIXA_THEME_SEMANTIC_WIRE_ADDED,
317 CAIXA_THEME_SEMANTIC_WIRE_REMOVED,
318 CAIXA_THEME_SEMANTIC_WIRE_UNCHANGED,
319 ];
320
321 /// Canonical kebab-case discriminator scalar for this variant — the
322 /// single substrate-primitive `&'static str` projection every
323 /// downstream consumer of the closed 16-arm [`Semantic`] partition
324 /// (a future LSP-side per-Semantic `SemanticTokenType` name-mapping
325 /// dispatch at `caixa-lsp/src/main.rs`, a future
326 /// `feira lint --list-styles` operator-facing enumeration verb, a
327 /// future `caixa.nvim` per-Semantic highlight-group name resolver
328 /// that reaches for a stable kebab identifier per arm, a future
329 /// `blackmatter-shell` per-arm classname the terminal emitter
330 /// composes into a `data-semantic="<kebab>"` attribute) reaches
331 /// through. Kebab-case matches the peer
332 /// [`gen_platform::IsVariant`]-derived kebab discriminant convention
333 /// the sibling closed-set typed enums
334 /// ([`caixa_core::CaixaKind::as_str`],
335 /// [`caixa_core::supervisor::RestartStrategy::as_str`],
336 /// [`caixa_core::supervisor::RestartPolicy::as_str`],
337 /// [`caixa_core::aplicacao::PlacementStrategy::as_str`],
338 /// [`caixa_core::upgrade::UpgradeInstruction::as_str`],
339 /// `caixa_lint::diagnostic::Severity::as_str`,
340 /// `caixa_lint::diagnostic::FixSafety::as_str`,
341 /// `caixa_arch::InvariantKind::as_str`,
342 /// `caixa_arch::ArchVerdict::as_str`,
343 /// `caixa_provedor::FerriteRuntime::variant_slug`) already emit
344 /// on their canonical `&'static str` projection axis.
345 ///
346 /// The 16 arms return the kebab-case forms of their `PascalCase`
347 /// variant names (`Keyword` → `"keyword"`, `KeywordArg` →
348 /// `"keyword-arg"`, `Unchanged` → `"unchanged"`, etc.), matching
349 /// the peer closed-set typed-enum canonical byte-string conventions.
350 ///
351 /// Peer of the [`std::fmt::Display`] and [`AsRef<str>`] impls on
352 /// this enum, which both route through this accessor so
353 /// `format!("{s}")`, `s.as_str()`, and
354 /// `<Semantic as AsRef<str>>::as_ref(&s)` resolve to the same
355 /// per-arm byte-string.
356 #[must_use]
357 pub const fn as_str(self) -> &'static str {
358 match self {
359 Self::Keyword => CAIXA_THEME_SEMANTIC_WIRE_KEYWORD,
360 Self::Symbol => CAIXA_THEME_SEMANTIC_WIRE_SYMBOL,
361 Self::KeywordArg => CAIXA_THEME_SEMANTIC_WIRE_KEYWORD_ARG,
362 Self::String => CAIXA_THEME_SEMANTIC_WIRE_STRING,
363 Self::Number => CAIXA_THEME_SEMANTIC_WIRE_NUMBER,
364 Self::Literal => CAIXA_THEME_SEMANTIC_WIRE_LITERAL,
365 Self::Comment => CAIXA_THEME_SEMANTIC_WIRE_COMMENT,
366 Self::Accent => CAIXA_THEME_SEMANTIC_WIRE_ACCENT,
367 Self::Muted => CAIXA_THEME_SEMANTIC_WIRE_MUTED,
368 Self::Error => CAIXA_THEME_SEMANTIC_WIRE_ERROR,
369 Self::Warning => CAIXA_THEME_SEMANTIC_WIRE_WARNING,
370 Self::Info => CAIXA_THEME_SEMANTIC_WIRE_INFO,
371 Self::Hint => CAIXA_THEME_SEMANTIC_WIRE_HINT,
372 Self::Added => CAIXA_THEME_SEMANTIC_WIRE_ADDED,
373 Self::Removed => CAIXA_THEME_SEMANTIC_WIRE_REMOVED,
374 Self::Unchanged => CAIXA_THEME_SEMANTIC_WIRE_UNCHANGED,
375 }
376 }
377
378 /// Reverse projection on the [`Semantic`] closed 16-arm enum's
379 /// canonical kebab-tag axis — parses a `"keyword"` / `"symbol"` /
380 /// `"keyword-arg"` / `"string"` / `"number"` / `"literal"` /
381 /// `"comment"` / `"accent"` / `"muted"` / `"error"` / `"warning"` /
382 /// `"info"` / `"hint"` / `"added"` / `"removed"` / `"unchanged"` wire
383 /// byte-string back to the typed enum, or returns `None` when `s`
384 /// lies outside the 16-arm accept-set [`Self::as_str`] emits. The
385 /// single `&str → Self` projection every future re-entry point on
386 /// the caixa-theme semantic-style axis dispatches through (a future
387 /// `feira lint --list-styles` operator-facing enumeration verb
388 /// hydrating a per-arm row from a stored kebab identifier back to
389 /// the typed enum before rendering, a future `caixa-lsp`-side
390 /// per-`SemanticTokenType` re-parse binding a prior
391 /// [`Self::as_str`] output back to the typed enum for
392 /// per-Semantic-highlight dispatch, a future `caixa.nvim` per-
393 /// Semantic highlight-group resolver re-loading a stored kebab
394 /// identifier back to the typed enum, a future `blackmatter-shell`
395 /// per-arm classname reverse-lookup binding a
396 /// `data-semantic="<kebab>"` DOM attribute back to the typed enum
397 /// for per-arm style dispatch, a `tracing::field::Value::Str`-arm
398 /// structured-log re-loader binding a prior emission's
399 /// [`Self::as_str`] output back to the typed enum for cross-run
400 /// per-Semantic-paint-histogram diff) would have had to re-inline a
401 /// 16-arm `match s` cascade that expressed no compile-time link back
402 /// to the substrate primitive.
403 ///
404 /// Same closed-set-reverse-projection discipline the sibling
405 /// [`caixa_core::CaixaKind::from_wire`] (2aa6d23),
406 /// [`caixa_core::CaixaDialeto::from_wire`] (d0e65ea),
407 /// [`caixa_core::supervisor::RestartStrategy::from_wire`] (4eec29c),
408 /// [`caixa_core::supervisor::RestartPolicy::from_wire`] (dd32ccf),
409 /// [`caixa_core::aplicacao::PlacementStrategy::from_wire`] (18c7342),
410 /// [`caixa_core::dep::DepList::from_wire`] (45ee563),
411 /// [`caixa_core::render::PathShapeViolation::from_wire`] (aebd9c6),
412 /// `caixa_arch::invariants::InvariantKind::from_wire` (b9e4e61),
413 /// `caixa_arch::report::ArchVerdict::from_wire` (6afe564),
414 /// `caixa_lint::diagnostic::Severity::from_wire` (5afff0e), and
415 /// `caixa_lint::diagnostic::FixSafety::from_wire` (bd505a1) typed
416 /// enums carry on the peer wire-side `str → Self` axes — extends
417 /// the substrate-wide `(as_str, from_wire)` round-trip family onto
418 /// the caixa-theme closed-set fieldless typed-enum axis (the first
419 /// closed-set fieldless typed enum on `caixa-theme` to converge on
420 /// the reverse-projection discipline), matching the same two-way
421 /// `str ↔ Self` round-trip every sibling closed-set enum already
422 /// carries. Method-named `from_wire` (not `from_str`) to match the
423 /// peer shapes verbatim and side-step a
424 /// `clippy::should_implement_trait` lint that a plain `from_str`
425 /// name would otherwise trigger without paired
426 /// [`std::str::FromStr`] impl scaffolding this axis does not carry
427 /// today. Returns `Option<Self>` (rather than `Result<Self, _>`) to
428 /// match the peer shapes: the caller picks the diagnostic form
429 /// appropriate for its use site (a `feira lint --list-styles` CLI
430 /// arg-parse renders its own per-verb error message; a future
431 /// admission-webhook rejection body wraps the `None` outcome with
432 /// the accepted-set enumeration `Semantic::ALL.iter().map(…)` for
433 /// operator diagnostics).
434 ///
435 /// Pinned load-bearing at the substrate-primitive level by
436 /// [`tests::semantic_from_wire_accepts_every_as_str_output`]
437 /// (round-trip witness against the peer [`Self::as_str`] axis) and
438 /// [`tests::semantic_from_wire_rejects_unknown_byte_strings`]
439 /// (rejection witness against silent accept-set widening).
440 #[must_use]
441 pub fn from_wire(s: &str) -> Option<Self> {
442 match s {
443 CAIXA_THEME_SEMANTIC_WIRE_KEYWORD => Some(Self::Keyword),
444 CAIXA_THEME_SEMANTIC_WIRE_SYMBOL => Some(Self::Symbol),
445 CAIXA_THEME_SEMANTIC_WIRE_KEYWORD_ARG => Some(Self::KeywordArg),
446 CAIXA_THEME_SEMANTIC_WIRE_STRING => Some(Self::String),
447 CAIXA_THEME_SEMANTIC_WIRE_NUMBER => Some(Self::Number),
448 CAIXA_THEME_SEMANTIC_WIRE_LITERAL => Some(Self::Literal),
449 CAIXA_THEME_SEMANTIC_WIRE_COMMENT => Some(Self::Comment),
450 CAIXA_THEME_SEMANTIC_WIRE_ACCENT => Some(Self::Accent),
451 CAIXA_THEME_SEMANTIC_WIRE_MUTED => Some(Self::Muted),
452 CAIXA_THEME_SEMANTIC_WIRE_ERROR => Some(Self::Error),
453 CAIXA_THEME_SEMANTIC_WIRE_WARNING => Some(Self::Warning),
454 CAIXA_THEME_SEMANTIC_WIRE_INFO => Some(Self::Info),
455 CAIXA_THEME_SEMANTIC_WIRE_HINT => Some(Self::Hint),
456 CAIXA_THEME_SEMANTIC_WIRE_ADDED => Some(Self::Added),
457 CAIXA_THEME_SEMANTIC_WIRE_REMOVED => Some(Self::Removed),
458 CAIXA_THEME_SEMANTIC_WIRE_UNCHANGED => Some(Self::Unchanged),
459 _ => None,
460 }
461 }
462}
463
464/// [`std::fmt::Display`] routed through [`Semantic::as_str`], so the
465/// pretty-printed byte-string every consumer that formats the semantic
466/// style as user-facing text lands on (a future `feira lint --list-styles`
467/// operator-facing enumeration verb's per-arm line, a future
468/// `caixa-lsp` diagnostic-source line naming the offending semantic,
469/// a future `caixa.nvim` per-Semantic highlight-group name emitter,
470/// a `tracing::field::display(&sem)` structured-log recorder on the
471/// paint-side emit path) reaches for the same lifted kebab-case
472/// per-arm byte-string [`Semantic::as_str`] returns.
473///
474/// Peer of the sibling [`std::fmt::Display`] impls on the closed-set
475/// typed enums the substrate carries — [`caixa_core::CaixaKind`],
476/// [`caixa_core::supervisor::RestartStrategy`],
477/// [`caixa_core::supervisor::RestartPolicy`],
478/// [`caixa_core::aplicacao::PlacementStrategy`],
479/// [`caixa_core::upgrade::UpgradeInstruction`],
480/// `caixa_lint::diagnostic::Severity`,
481/// `caixa_lint::diagnostic::FixSafety`,
482/// `caixa_arch::InvariantKind`, `caixa_arch::ArchVerdict`,
483/// `caixa_provedor::FerriteRuntime` — extended to the second-to-last
484/// un-lifted `caixa-theme` closed-set fieldless typed enum on the
485/// substrate-wide `(as_str, AsRef<str>, Display)` canonical-projection
486/// triple ratchet the prior lifts converged onto.
487impl std::fmt::Display for Semantic {
488 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
489 f.write_str(self.as_str())
490 }
491}
492
493/// Substrate-canonical [`AsRef<str>`] projection on the caixa-theme
494/// [`Semantic`] closed-set fieldless typed enum — routes through the
495/// same [`Semantic::as_str`] `pub const fn` scalar accessor the paired
496/// [`std::fmt::Display`] impl already reaches for.
497///
498/// Peer of the sibling [`AsRef<str>`] impls the substrate carries on
499/// [`caixa_core::CaixaKind`], [`caixa_core::CaixaVersion`],
500/// [`caixa_core::CaixaDialeto`], [`caixa_core::dep::DepList`],
501/// [`caixa_core::supervisor::RestartStrategy`],
502/// [`caixa_core::supervisor::RestartPolicy`],
503/// [`caixa_core::aplicacao::PlacementStrategy`],
504/// [`caixa_core::aplicacao::RateLimitUnit`],
505/// `caixa_lint::diagnostic::Severity`,
506/// `caixa_arch::InvariantKind`, `caixa_arch::ArchVerdict`,
507/// `caixa_provedor::FerriteRuntime` — extends the substrate-wide
508/// `(as_str, AsRef<str>, Display)` canonical-projection triple onto
509/// the caixa-theme closed-set typed-enum axis, so a future consumer
510/// bound through the trait-idiomatic `.as_ref()` (a
511/// `HashMap::get::<str>(sem.as_ref())` per-Semantic style-lookup, a
512/// future `caixa-lsp` `SemanticTokenType::new(sem.as_ref())`
513/// registration site, any `impl AsRef<str>`-bound generic function)
514/// reaches the same kebab byte-string [`Semantic::as_str`] returns
515/// rather than an open-coded `.as_str()` projection at every
516/// wire-up.
517impl AsRef<str> for Semantic {
518 fn as_ref(&self) -> &str {
519 self.as_str()
520 }
521}
522
523/// Trait-idiomatic reverse projection on the [`Semantic`] closed 16-arm
524/// caixa-theme semantic-style axis — routes byte-for-byte through the
525/// paired substrate-primitive [`Semantic::from_wire`] `Option<Self>`
526/// accessor so every future consumer that binds a canonical semantic
527/// tag through the standard-library `.try_into()` / [`TryFrom`] axis
528/// (a future `feira lint --semantic=<kebab>` CLI arg-parse that
529/// composes into `let sem: Semantic = s.try_into()?`, a future
530/// `caixa-lsp` per-token re-parse hydrating a prior
531/// [`Semantic::as_str`] output back to the typed enum for
532/// `SemanticTokenType` dispatch, a future `caixa.nvim` per-highlight-
533/// group re-loader binding a stored kebab byte-string back through the
534/// typed enum, a generic `<T: TryFrom<&str>>`-bound theme-overlay
535/// re-loader over any of the substrate's closed-set typed enums)
536/// reaches the same 16-arm accept-set the sibling
537/// [`Semantic::from_wire`] resolver parses through and the sibling
538/// [`Semantic::as_str`] emits, rather than an open-coded per-arm
539/// `match s { "keyword" => …, "symbol" => …, … _ => … }` cascade whose
540/// arm-set has no compile-time link back to the substrate primitive.
541///
542/// Complements the pre-existing forward-projection triple
543/// ([`std::fmt::Display`], [`AsRef<str>`], [`Semantic::as_str`]) with
544/// the paired trait-idiomatic reverse-projection axis: Rust-side
545/// newtype/typed-enum convention pairs [`AsRef<str>`] with either
546/// [`std::str::FromStr`] or [`TryFrom<&str>`] on the same primitive so
547/// a caller who can project *out to* a `&str` can also project *in
548/// from* one. The [`TryFrom<&str>`] axis is deliberately chosen over
549/// [`std::str::FromStr`] to sidestep the `clippy::should_implement_trait`
550/// lint the sibling method-named [`Semantic::from_wire`] would trigger
551/// under a `FromStr` impl (the same design tradeoff the peer
552/// [`caixa_core::CaixaKind`] (3c83606),
553/// [`caixa_core::CaixaDialeto`] (bf33136),
554/// [`caixa_core::aplicacao::PlacementStrategy`] (6fd00cd),
555/// [`caixa_core::supervisor::RestartStrategy`] (5b828ed),
556/// [`caixa_core::supervisor::RestartPolicy`] (6fdd0d9),
557/// [`caixa_core::aplicacao::WitShape`] (5472902),
558/// [`caixa_core::aplicacao::RateLimitUnit`] (bf78400),
559/// [`caixa_core::render::PathShapeViolation`] (e67e48a),
560/// `caixa_arch::invariants::InvariantKind` (e21a857),
561/// `caixa_arch::report::ArchVerdict` (0a4cc45),
562/// `caixa_lint::diagnostic::Severity` (a7bf74c), and
563/// `caixa_lint::diagnostic::FixSafety` (df86c94) blocks note) — this
564/// impl closes the trait-idiomatic reverse axis without disturbing the
565/// method-named `from_wire` shape every peer closed-set typed enum
566/// already carries.
567///
568/// `type Error = ()` matches the sibling [`Semantic::from_wire`]'s
569/// `Option<Self>` return-shape's deliberate deferral of error typing:
570/// the caller picks the diagnostic form appropriate for its use site
571/// (a future `feira lint --semantic` CLI arg-parse composes its own
572/// per-verb "unknown semantic-style tag: <arg> — accepted: {…}"
573/// message enumerating [`Semantic::ALL`], a future admission-webhook
574/// rejection body wraps the `Err(())` outcome with the accepted-set
575/// enumeration for operator diagnostics, a `Result::map_err` at the
576/// call site lifts the axis-error to a per-verb error type). Same
577/// shape the peer sibling reverse-projection axes carry. The return-
578/// shape uses fully-qualified `<Self as TryFrom<&str>>::Error` because
579/// the associated-type name would otherwise collide with the
580/// [`Self::Error`] variant on the same primitive (the identical
581/// ambiguous-associated-item defect the sibling
582/// `impl TryFrom<&str> for Severity` (a7bf74c) already threads around
583/// under `#[deny(future_incompatible)]`).
584///
585/// The paired [`TryFrom<&str>`] impl reaches the same 16-arm accept-
586/// set the [`Semantic::from_wire`] resolver dispatches through, so any
587/// future arm addition (a `Namespace` tier between [`Self::Symbol`]
588/// and [`Self::KeywordArg`] for the M4 tatara-lisp module system's
589/// qualified-name semantic-token dispatch, a `Deleted` tier for a
590/// hard-delete-mark distinct from [`Self::Removed`] the future 3-way
591/// diff surface grows — both trajectory items the sibling
592/// [`Semantic::ALL`] doc block already names) grows the trait-
593/// idiomatic axis by construction: one caixa-theme edit on
594/// [`Semantic::from_wire`] extends both the method-named reverse
595/// projection every existing consumer keys off and the trait-
596/// idiomatic reverse projection this impl exposes, without a
597/// coordinated rewrite across every future `TryFrom<&str>`-bound
598/// consumer's arm-set.
599///
600/// Extends the substrate-wide closed-set-enum trait-idiomatic
601/// reverse-projection family ([`caixa_core::CaixaKind`] via 3c83606,
602/// [`caixa_core::CaixaDialeto`] via bf33136,
603/// [`caixa_core::aplicacao::PlacementStrategy`] via 6fd00cd,
604/// [`caixa_core::supervisor::RestartStrategy`] via 5b828ed,
605/// [`caixa_core::supervisor::RestartPolicy`] via 6fdd0d9,
606/// [`caixa_core::aplicacao::WitShape`] via 5472902,
607/// [`caixa_core::aplicacao::RateLimitUnit`] via bf78400,
608/// [`caixa_core::render::PathShapeViolation`] via e67e48a,
609/// `caixa_arch::invariants::InvariantKind` via e21a857,
610/// `caixa_arch::report::ArchVerdict` via 0a4cc45,
611/// `caixa_lint::diagnostic::Severity` via a7bf74c, and
612/// `caixa_lint::diagnostic::FixSafety` via df86c94) onto the first
613/// closed-set fieldless typed enum on the caixa-theme surface — the
614/// semantic-style 16-arm accept-set every per-Semantic paint dispatch,
615/// every future `caixa-lsp` per-SemanticTokenType wire-up, and every
616/// future `caixa.nvim` per-highlight-group re-loader keys off. The
617/// thirteenth peer on the substrate surface, and the first inside
618/// `caixa-theme`; with `caixa_provedor::FerriteRuntime` remaining as
619/// the only outside-caixa-core closed-set fieldless typed enum whose
620/// trait-idiomatic axis is still open.
621///
622/// Pinned load-bearing by
623/// [`tests::semantic_try_from_str_routes_through_from_wire_accessor`]
624/// (byte-parity pin against [`Semantic::from_wire`] across the 16-arm
625/// accept-set) and
626/// [`tests::semantic_try_from_str_rejects_unknown_byte_strings`]
627/// (rejection witness against silent accept-set widening).
628impl TryFrom<&str> for Semantic {
629 type Error = ();
630
631 fn try_from(s: &str) -> Result<Self, <Self as TryFrom<&str>>::Error> {
632 Self::from_wire(s).ok_or(())
633 }
634}
635
636/// Standard-library trait-idiomatic [`std::str::FromStr`] impl on the
637/// [`Semantic`] closed-set caixa-theme semantic-style typed enum —
638/// routes byte-for-byte through the paired
639/// [`TryFrom<&str> for Semantic`] impl (which in turn routes through
640/// the substrate-primitive [`Semantic::from_wire`] `Option<Self>`
641/// accessor), so `"...".parse::<Semantic>()` /
642/// `<Semantic as FromStr>::from_str(…)` reaches the same 16-arm
643/// canonical-lowercase-kebab accept-set the sibling method-named
644/// [`Semantic::from_wire`] resolver and the paired [`TryFrom<&str>`]
645/// impl already resolve against.
646///
647/// Extends the substrate-wide trait-idiomatic `str::parse`-axis
648/// campaign — opened on [`caixa_core::dep::DepList`] via 6167092 as
649/// first-mover on the two-list dep-graph closed-set typed enum, then
650/// extended onto [`caixa_core::CaixaKind`] (9867432),
651/// [`caixa_core::aplicacao::PlacementStrategy`] (62ef49a),
652/// [`caixa_core::CaixaDialeto`] (ff01b2f),
653/// [`caixa_arch::invariants::InvariantKind`] (fb16072),
654/// [`caixa_arch::report::ArchVerdict`] (40e9dfd),
655/// `caixa_lint::diagnostic::Severity` (6b0a08c),
656/// `caixa_lint::diagnostic::FixSafety` (eb6942b), and
657/// [`caixa_core::render::PathShapeViolation`] (b0b578c) — onto the
658/// *first* closed-set fieldless typed enum on the caixa-theme surface:
659/// the 16-arm semantic-style accept-set every per-`Semantic` paint
660/// dispatch, every future `caixa-lsp`-side per-`SemanticTokenType`
661/// wire-up, every future `caixa.nvim` per-highlight-group re-loader,
662/// and every future `blackmatter-shell` per-arm
663/// `data-semantic="<kebab>"` DOM-attribute emission dispatches through.
664/// Coherent by construction on this enum specifically: [`Semantic`]
665/// carries exactly one canonical-lowercase-kebab wire axis with no
666/// paired secondary parse surface, so — unlike the peer
667/// [`caixa_core::supervisor::RestartStrategy`] /
668/// [`caixa_core::supervisor::RestartPolicy`] (whose paired
669/// [`gen_platform::FromStrKind`]-derived kebab-case `FromStr` on the
670/// dispatcher-catalog axis rules a second `FromStr` impl out by
671/// coherence) and unlike the peer
672/// [`caixa_core::aplicacao::WitShape`] /
673/// [`caixa_core::aplicacao::RateLimitUnit`] (whose two-axis splits
674/// motivate deliberate deferral of the `FromStr` axis so a plain
675/// `s.parse::<T>()` cannot obscure which axis the caller reaches),
676/// lifting [`FromStr`] onto [`Semantic`] cannot collide with a second
677/// parse axis it does not carry.
678///
679/// [`FromStr`] is the canonical Rust-idiomatic parse-set entry point
680/// every stdlib-shaped consumer reaches for — [`str::parse::<T>()`]
681/// is a `T: FromStr`-bounded generic, not a
682/// `T: for<'a> TryFrom<&'a str>`-bounded one — so lifting [`FromStr`]
683/// onto the closed-set enum unlocks the `.parse::<Semantic>()`
684/// short-form on every consumer (a future
685/// `feira lint --list-styles=<semantic>` clap-style arg-parse composes
686/// `arg.parse::<Semantic>()`; a `serde` string-tagged deserializer with
687/// a `#[serde(with = "serde_with::DisplayFromStr")]` shim routes
688/// through the same `FromStr` bound; a future `caixa-lsp`-side
689/// per-`SemanticTokenType` startup registration walk that reads a
690/// declaration-order kebab list from configuration reaches the typed
691/// enum through `line.parse::<Semantic>()` without a per-consumer
692/// [`TryFrom<&str>`] restatement; a `caixa.nvim`-side
693/// per-highlight-group re-loader binding a prior emission's
694/// [`Semantic::as_str`] output back to the typed enum for cross-run
695/// palette-histogram diff reaches the same axis through the stdlib
696/// `.parse()` short-form; a future `blackmatter-shell`
697/// `data-semantic="<kebab>"` DOM-attribute round-trip that walks
698/// `element.dataset.semantic.parse::<Semantic>()` on the client-side
699/// paint dispatch reaches the same axis through the stdlib
700/// short-form).
701///
702/// The impl trivially delegates to the paired [`TryFrom<&str>`] — same
703/// `type Err = ()` deliberate-deferral shape the sibling
704/// reverse-projection trait carries — so both trait-idiomatic
705/// parse-axis paths (`TryFrom<&str>` and `FromStr::from_str`) resolve
706/// to the same 16-arm accept-set by construction. A future arm
707/// addition (a `Deprecated` decoration between [`Self::Removed`] and
708/// [`Self::Unchanged`] the future formatter-preview grows to mark
709/// soft-delete regions distinct from hard-delete [`Self::Removed`] the
710/// future 3-way diff surface grows — the trajectory item the sibling
711/// [`Semantic::ALL`] doc block already names) reaches every parse path
712/// through one caixa-theme edit on the substrate-primitive
713/// [`Semantic::from_wire`] accessor, not a coordinated rewrite across
714/// the two reverse-projection trait impls.
715///
716/// Pinned load-bearing by
717/// [`tests::semantic_from_str_routes_through_try_from_str_impl`]
718/// (byte-parity pin across the 16-arm accept-set + delegated
719/// `.parse()`-projection witness) and
720/// [`tests::semantic_from_str_rejects_unknown_byte_strings`]
721/// (rejection witness against silent accept-set widening).
722impl std::str::FromStr for Semantic {
723 type Err = ();
724
725 fn from_str(s: &str) -> Result<Self, Self::Err> {
726 <Self as TryFrom<&str>>::try_from(s)
727 }
728}
729
730/// Standard-library trait-idiomatic forward projection on the
731/// [`Semantic`] closed 16-arm caixa-theme semantic-style axis. Routes
732/// byte-for-byte through the paired substrate-primitive
733/// [`Semantic::as_str`] `pub const fn` accessor so
734/// `<&'static str>::from(sem)` / `sem.into::<&'static str>()` reaches
735/// the same 16-arm canonical-lowercase kebab emit-set the sibling
736/// method-named accessor dispatches through and the sibling
737/// [`std::fmt::Display for Semantic`] / [`AsRef<str> for Semantic`]
738/// impls also route through.
739///
740/// Extends the substrate-wide closed-set-enum trait-idiomatic
741/// forward-projection family
742/// ([`caixa_core::supervisor::RestartStrategy`] via 523157d,
743/// [`caixa_core::supervisor::RestartPolicy`] via 9fb37d0,
744/// [`caixa_core::CaixaKind`] via edb827b,
745/// [`caixa_core::CaixaDialeto`] via c189a6f,
746/// [`caixa_core::aplicacao::PlacementStrategy`] via afa3562,
747/// [`caixa_core::aplicacao::WitShape`] via 56998ec,
748/// [`caixa_core::aplicacao::RateLimitUnit`] via 7fdfbf4,
749/// [`caixa_core::render::PathShapeViolation`] via 070a6de,
750/// [`caixa_arch::invariants::InvariantKind`] via f2ca7bc,
751/// [`caixa_arch::report::ArchVerdict`] via d4559cb,
752/// `caixa_lint::diagnostic::Severity` via 5cc3b8b, and
753/// `caixa_lint::diagnostic::FixSafety` via 2a56127) onto the first
754/// closed-set fieldless typed enum on the caixa-theme surface — the
755/// semantic-style 16-arm accept-set every per-Semantic paint dispatch,
756/// every future `caixa-lsp` per-`SemanticTokenType` wire-up, every
757/// future `caixa.nvim` per-highlight-group re-loader, and every future
758/// `blackmatter-shell` per-arm `data-semantic="<kebab>"` DOM emission
759/// keys off. The thirteenth peer on the substrate surface, closing the
760/// caixa-theme closed-set fieldless typed-enum axis onto the trait-
761/// idiomatic forward-projection axis and matching the paired trait-
762/// idiomatic reverse-projection axis (already closed via bd7da69 on
763/// this enum), with only `caixa_provedor::FerriteRuntime` remaining as
764/// the last outside-caixa-core closed-set fieldless typed enum whose
765/// trait-idiomatic forward axis is still open.
766///
767/// Pairs with the sibling [`TryFrom<&str> for Semantic`] impl (bd7da69)
768/// to close the two-way `Self ↔ &'static str` round-trip on the
769/// trait-idiomatic axis pair, mirroring the pre-existing method-named
770/// [`Semantic::as_str`] + [`Semantic::from_wire`] pair on the
771/// substrate-primitive axis pair.
772///
773/// Return type is `&'static str` by construction — every
774/// [`Semantic::as_str`] arm resolves to an inline `"keyword"` /
775/// `"symbol"` / `"keyword-arg"` / `"string"` / `"number"` /
776/// `"literal"` / `"comment"` / `"accent"` / `"muted"` / `"error"` /
777/// `"warning"` / `"info"` / `"hint"` / `"added"` / `"removed"` /
778/// `"unchanged"` `&'static str` literal, so the trait's return-type
779/// promise is upheld structurally without a [`String::leak`] cast or a
780/// per-arm inline literal outside the paired [`Semantic::as_str`]
781/// dispatch.
782///
783/// The paired [`Semantic::as_str`] accessor's 16-arm emit-set is the
784/// single source of truth — every future arm addition (a `Namespace`
785/// tier between [`Self::Symbol`] and [`Self::KeywordArg`] for the M4
786/// tatara-lisp module system's qualified-name semantic-token dispatch,
787/// a `Deleted` tier for a hard-delete-mark distinct from
788/// [`Self::Removed`] the future 3-way diff surface grows — both
789/// trajectory items the sibling [`Semantic::ALL`] doc block already
790/// names) grows the trait-idiomatic forward axis by construction: one
791/// caixa-theme edit on [`Semantic::as_str`] extends every one of the
792/// sibling forward-projection paths ([`std::fmt::Display`],
793/// [`AsRef<str>`], [`Semantic::as_str`] itself, and this
794/// [`From<Self> for &'static str`]) without a coordinated rewrite
795/// across every future `Into<&'static str>`-bound consumer's arm-set.
796///
797/// Pinned load-bearing by
798/// [`tests::semantic_from_into_static_str_routes_through_as_str_accessor`]
799/// (byte-parity pin against [`Semantic::as_str`] across the 16-arm
800/// emit-set, plus a `const`-context materialization witness for the
801/// `&'static str` lifetime promise routed through the paired
802/// [`Semantic::as_str`] `pub const fn` accessor, plus a paired
803/// `.into()` shape assertion covering the blanket-derived
804/// `Into<&'static str>` shape) and
805/// [`tests::semantic_from_into_static_str_and_as_str_partition_the_emit_set`]
806/// (partition pin asserting `<&'static str as From<Semantic>>::from`
807/// and [`Semantic::as_str`] agree on every arm, plus a two-way direct
808/// round-trip witness through the paired trait-idiomatic
809/// [`TryFrom<&str>`] axis that closes the two-way
810/// `Self ↔ &'static str` round-trip on the trait-idiomatic axis pair
811/// — the emit-side [`Semantic::as_str`] and the parse-side
812/// [`Semantic::from_wire`] dispatch on the same 16 inline canonical-
813/// lowercase kebab byte-strings by construction, so round-tripping
814/// composes the two trait impls directly).
815impl From<Semantic> for &'static str {
816 fn from(sem: Semantic) -> &'static str {
817 sem.as_str()
818 }
819}
820
821/// Trait-idiomatic *borrowed-input* forward projection on the
822/// [`Semantic`] closed 16-arm caixa-theme semantic-style axis onto the
823/// `&'static str` axis — the borrowed-input companion to the paired
824/// owned-input [`From<Semantic> for &'static str`] impl immediately
825/// above. Routes byte-for-byte through the same substrate-primitive
826/// [`Semantic::as_str`] `pub const fn` accessor so every consumer that
827/// binds a `&Semantic` through the standard-library `.into()` /
828/// [`From<&Self> for &'static str`] axis (a
829/// `Semantic::ALL.iter().map(<&'static str>::from).collect::<Vec<_>>()`
830/// per-arm accept-set materializer — whose iterator over
831/// `&'static [Semantic]` yields `&Semantic`, not `Semantic`, so the
832/// owned-input [`From<Semantic>`] axis alone forces every call site
833/// through an explicit `.copied()` / dereference / [`Copy`]-bound
834/// restatement rather than the direct trait-idiomatic projection; a
835/// future `feira lint --list-styles` operator-facing enumeration verb
836/// composed via `Semantic::ALL.iter().map(Into::into)`; a future
837/// `caixa-lsp` per-`SemanticTokenType` registration walk that borrows
838/// `&Semantic` off a stored per-style row; a future `caixa.nvim` per-
839/// highlight-group re-loader that borrows `&Semantic` off the loaded
840/// theme-overlay table; a future
841/// `HashMap::<&'static str, _>::from_iter(Semantic::ALL.iter().map(
842/// |sem| (<&'static str>::from(sem), 0)))` per-Semantic-paint
843/// histogram seed a future `blackmatter-shell` per-arm
844/// `data-semantic="<kebab>"` DOM-attribute emit path composes) reaches
845/// the same 16-arm `"keyword"` / `"symbol"` / `"keyword-arg"` /
846/// `"string"` / `"number"` / `"literal"` / `"comment"` / `"accent"` /
847/// `"muted"` / `"error"` / `"warning"` / `"info"` / `"hint"` /
848/// `"added"` / `"removed"` / `"unchanged"` canonical-lowercase kebab
849/// emit-set the paired owned-input [`From<Semantic> for &'static str`],
850/// the sibling [`std::fmt::Display`], [`AsRef<str>`], and
851/// [`Semantic::as_str`] surfaces already return.
852///
853/// Fifteenth and final peer on the substrate-wide trait-idiomatic
854/// *borrowed-input* `&'static str`-returning forward-projection family
855/// already carried by [`caixa_core::dep::DepList`] (64aa742,
856/// first-mover), [`caixa_core::CaixaKind`],
857/// [`caixa_core::CaixaDialeto`],
858/// [`caixa_core::supervisor::RestartStrategy`],
859/// [`caixa_core::supervisor::RestartPolicy`],
860/// [`caixa_core::aplicacao::PlacementStrategy`],
861/// [`caixa_core::aplicacao::WitShape`],
862/// [`caixa_core::aplicacao::RateLimitUnit`],
863/// [`caixa_core::render::PathShapeViolation`] (cdf4e95, first render-
864/// side arm), [`caixa_arch::invariants::InvariantKind`] (238d886,
865/// first outside-`caixa-core` arm), [`caixa_arch::report::ArchVerdict`]
866/// (73bda50), `caixa_lint::diagnostic::Severity` (2b9003f),
867/// `caixa_lint::diagnostic::FixSafety` (d8769ab), and
868/// `caixa_provedor::FerriteRuntime` (676d693). Rust's `From` trait does
869/// not auto-derive the `From<&Self>` sibling from a `From<Self>` impl
870/// (the blanket `impl<T, U> From<&T> for U where T: Copy, U: From<T>`
871/// does not exist in `core`), so every closed-set typed enum that
872/// carries the owned-input axis but not the borrowed-input axis forces
873/// every borrowed-input call site through a `.copied()` /
874/// `<&'static str>::from(*sem)` / `sem.as_str()` detour whose type
875/// bounds have no compile-time link to the substrate primitive.
876/// Lifting the borrowed-input axis on the caixa-theme semantic-style
877/// 16-arm closed-set fieldless typed enum closes that gap on the same
878/// trajectory the paired owned-input axis
879/// ([`impl From<Semantic> for &'static str`] immediately above) already
880/// opened, and closes the trait-idiomatic *borrowed-input*
881/// `&'static str`-returning axis on the last remaining substrate-wide
882/// closed-set fieldless typed enum whose borrowed-input axis was still
883/// open — the substrate-wide 2×2-completion campaign now covers every
884/// closed-set fieldless typed enum on the caixa surface on the
885/// borrowed-input `&'static str`-returning axis.
886///
887/// Pinned load-bearing by
888/// [`tests::semantic_from_borrowed_into_static_str_routes_through_as_str_accessor`]
889/// (byte-parity pin against [`Semantic::as_str`] across the 16-arm
890/// emit-set via a borrowed input, plus a `const`-context
891/// materialization witness for the `&'static str` lifetime promise)
892/// and
893/// [`tests::semantic_from_owned_and_borrowed_into_static_str_agree_on_every_arm`]
894/// (cross-axis partition pin against the paired owned-input
895/// [`From<Semantic> for &'static str`] impl, plus a
896/// `.iter().map(Into::into)` pipe witness over [`Semantic::ALL`] whose
897/// iterator yields `&Semantic` by construction so this borrowed-input
898/// axis is what routes the pipe through the substrate-primitive
899/// accessor without a spurious `Copy` deref).
900impl From<&Semantic> for &'static str {
901 fn from(sem: &Semantic) -> &'static str {
902 sem.as_str()
903 }
904}
905
906/// Trait-idiomatic *owned-input, owned-`String` output* forward
907/// projection on the [`Semantic`] closed 16-arm caixa-theme
908/// semantic-style axis — the owned-`String` companion to the paired
909/// [`From<Semantic> for &'static str`] and
910/// [`From<&Semantic> for &'static str`] siblings immediately above.
911/// Routes byte-for-byte through the substrate-primitive
912/// [`Semantic::as_str`] `pub const fn` accessor via
913/// [`str::to_owned`] so every consumer that binds a [`Semantic`]
914/// through the standard-library `.into()` / [`From<Self> for String`]
915/// axis (a `let key: String = sem.into();`-shaped downstream call
916/// site; a future `serde_json::Value::String(sem.into())` structured-
917/// payload composer where the `Value::String` arm typing demands an
918/// owned [`String`] and the sibling `&'static str`-returning axes
919/// force an explicit `.to_owned()` / [`String::from`] restatement at
920/// every call site; a future
921/// `HashMap::<String, Semantic>::from_iter` per-semantic lookup on
922/// a future `caixa-lsp` per-`SemanticTokenType` registration path
923/// where the map's key type is owned [`String`] rather than
924/// `&'static str`; a future
925/// [`std::borrow::Cow::<'static, str>::Owned(sem.into())`] composer
926/// on a future `feira lint --list-styles` operator-facing enumeration
927/// verb's per-arm row where an owned [`Cow`] arm typing rules;
928/// a future `caixa.nvim` per-highlight-group re-loader that stores
929/// the per-Semantic kebab identifier as an owned [`String`] on the
930/// theme-overlay table; a future `blackmatter-shell` per-arm
931/// `data-semantic="<kebab>"` DOM emission whose serializer's
932/// [`Serialize`] impl on [`String`] owns the emit-path) reaches the
933/// same 16-arm `"keyword"` / `"symbol"` / `"keyword-arg"` /
934/// `"string"` / `"number"` / `"literal"` / `"comment"` / `"accent"` /
935/// `"muted"` / `"error"` / `"warning"` / `"info"` / `"hint"` /
936/// `"added"` / `"removed"` / `"unchanged"` canonical-lowercase kebab
937/// emit-set the paired `&'static str`-returning axes, the sibling
938/// [`std::fmt::Display`], [`AsRef<str>`], and [`Semantic::as_str`]
939/// surfaces already return — no `.to_owned()` /
940/// `String::from(sem.as_str())` detour whose type bounds have no
941/// compile-time link to the substrate primitive.
942///
943/// Rust's standard library does not carry a blanket
944/// `impl<T: AsRef<str>> From<T> for String` (nor an
945/// `impl<T: fmt::Display> From<T> for String`), so every closed-set
946/// typed enum that carries the paired [`AsRef<str>`] /
947/// [`std::fmt::Display`] / [`From<Self> for &'static str`] /
948/// [`From<&Self> for &'static str`] quadruple but not the owned-
949/// `String` axis forces every owned-string call site through the
950/// detour above. This lift closes that axis on the sole closed-set
951/// fieldless typed enum on the caixa-theme surface (the semantic-
952/// style 16-arm axis), extending the substrate-wide
953/// `{Self, &Self} × {&'static str, String}` 2×2-completion campaign
954/// onto the sixth outside-`caixa-core` closed-set fieldless typed
955/// enum on the caixa surface — matching the trajectory each of the
956/// twelve prior peer enums —
957/// [`caixa_core::supervisor::RestartStrategy`] (7baa18a, first-mover
958/// on this axis), [`caixa_core::supervisor::RestartPolicy`] (7851725),
959/// [`caixa_core::CaixaKind`] (231a18c),
960/// [`caixa_core::CaixaDialeto`] (88942cd),
961/// [`caixa_core::dep::DepList`] (32b0ee8),
962/// [`caixa_core::aplicacao::PlacementStrategy`] (1154c2f),
963/// [`caixa_core::aplicacao::WitShape`] (79a8723),
964/// [`caixa_core::aplicacao::RateLimitUnit`] (c7d687d),
965/// [`caixa_core::render::PathShapeViolation`] (6e0479a, first render-
966/// side arm), [`caixa_arch::invariants::InvariantKind`] (1afd8d5,
967/// first outside-`caixa-core` arm — the paired severity-classification
968/// axis on the caixa-arch invariant-kind closed-set enum),
969/// [`caixa_arch::report::ArchVerdict`] (cc80a53, the paired verdict-
970/// outcome axis on the sibling caixa-arch closed-set enum),
971/// `caixa_lint::diagnostic::Severity` (4635d4e),
972/// `caixa_lint::diagnostic::FixSafety` (e4d73c6), and
973/// `caixa_provedor::FerriteRuntime` (1e14fde, the paired ferrite-
974/// runtime axis on the sole caixa-provedor closed-set enum) —
975/// followed on the same 2×2-completion campaign.
976///
977/// Pinned load-bearing by
978/// [`tests::semantic_from_into_owned_string_routes_through_as_str_accessor`]
979/// (byte-parity pin against [`Semantic::as_str`] across the 16-arm
980/// emit-set via the owned-`String` surface, plus a blanket-derived
981/// `Into<String>` shape witness) and
982/// [`tests::semantic_from_into_owned_string_and_static_str_agree_on_every_arm`]
983/// (cross-axis partition pin against the paired owned-input
984/// `&'static str`-returning [`From<Semantic> for &'static str`] impl
985/// and the [`ToString::to_string`]-through-[`std::fmt::Display`]
986/// surface, plus a `.iter().copied().map(String::from)` pipe witness
987/// over [`Semantic::ALL`], plus a direct `Self → String → Self`
988/// round-trip witness through the paired [`TryFrom<&str>`] axis on
989/// the owned-[`String`]'s [`String::as_str`] borrow).
990impl From<Semantic> for String {
991 fn from(sem: Semantic) -> String {
992 sem.as_str().to_owned()
993 }
994}
995
996/// Trait-idiomatic *borrowed-input, owned-`String` output* forward
997/// projection on the [`Semantic`] closed 16-arm caixa-theme semantic-
998/// style axis — the borrowed-input companion to the paired owned-
999/// input [`From<Semantic> for String`] (5ea146c) immediately above,
1000/// the paired borrowed-input [`From<&Semantic> for &'static str`]
1001/// (ffc0f26), and the paired owned-input
1002/// [`From<Semantic> for &'static str`] siblings above. Routes byte-
1003/// for-byte through the substrate-primitive [`Semantic::as_str`]
1004/// `pub const fn` accessor via [`str::to_owned`] so every consumer
1005/// that binds a [`Semantic`] through the standard-library `.into()` /
1006/// [`From<&Self> for String`] axis reaches the same 16-arm
1007/// `"keyword"` / `"symbol"` / `"keyword-arg"` / `"string"` /
1008/// `"number"` / `"literal"` / `"comment"` / `"accent"` / `"muted"` /
1009/// `"error"` / `"warning"` / `"info"` / `"hint"` / `"added"` /
1010/// `"removed"` / `"unchanged"` canonical-lowercase kebab emit-set
1011/// the paired [`std::fmt::Display`], [`AsRef<str>`],
1012/// [`Semantic::as_str`], and the three other trait-idiomatic
1013/// forward-projection impls already return — no
1014/// `sem.as_str().to_owned()` / `String::from(*sem)` (with a spurious
1015/// [`Copy`] deref) / `sem.to_string()` (through
1016/// [`std::fmt::Display`]) detour whose type bounds have no compile-
1017/// time link to the substrate primitive.
1018///
1019/// Fills the *last* remaining corner of the substrate-wide
1020/// `{Self, &Self} × {&'static str, String}` 2×2 trait-idiomatic
1021/// projection family on the sole closed-set fieldless typed enum on
1022/// the caixa-theme surface — and, by construction, the *final*
1023/// corner on the *entire* substrate-wide closed-set fieldless typed-
1024/// enum roster on the caixa surface, closing the substrate-wide
1025/// 2×2-completion campaign that opened on
1026/// [`caixa_core::supervisor::RestartStrategy`] (579385f, first-mover
1027/// on the borrowed-input owned-[`String`] axis). Rust's standard
1028/// library carries no blanket
1029/// `impl<T: AsRef<str>> From<&T> for String` (nor an
1030/// `impl<T: fmt::Display> From<&T> for String`), so every borrowed-
1031/// input owned-string call site — a future
1032/// `serde_json::Value::String(String::from(&sem))` structured-payload
1033/// composer over a borrowed per-style row where the
1034/// [`serde_json::Value::String`] arm typing demands an owned
1035/// [`String`] and the sibling `&'static str`-returning axes force an
1036/// explicit `.to_owned()` / [`String::from`] restatement, a future
1037/// `Semantic::ALL.iter().map(String::from).collect::<Vec<_>>()` per-
1038/// arm accept-set materializer on a future `feira lint --list-styles`
1039/// operator-facing enumeration verb whose iterator yields `&Semantic`
1040/// by construction (so the borrowed-input owned-[`String`] axis is
1041/// what routes the pipe through the substrate-primitive
1042/// [`Semantic::as_str`] accessor without a spurious `.copied()` /
1043/// [`Copy`]-bound dereference), a future
1044/// `HashMap::<String, usize>::from_iter(Semantic::ALL.iter().map(|sem| (String::from(sem), 0)))`
1045/// per-Semantic-paint histogram seed a future `blackmatter-shell`
1046/// per-arm `data-semantic="<kebab>"` DOM-attribute emit path
1047/// composes off a borrowed `&Semantic` off the loaded theme-overlay
1048/// table, a future `caixa-lsp` per-`SemanticTokenType` registration
1049/// walk borrowing off a stored per-style row, a future `caixa.nvim`
1050/// per-highlight-group re-loader borrowing off the loaded theme-
1051/// overlay table where the runtime stores the owned kebab identifier
1052/// as [`String`] — otherwise resolves through the detour above.
1053///
1054/// Closing this corner locks the caixa-theme semantic-style enum's
1055/// whole 2×2 trait-idiomatic projection family onto a single
1056/// [`Semantic::as_str`]-routed emit-set — any future arm addition (a
1057/// `Namespace` tier between [`Self::Symbol`] and [`Self::KeywordArg`]
1058/// for the M4 tatara-lisp module system's qualified-name semantic-
1059/// token dispatch, a `Deleted` tier for a hard-delete-mark distinct
1060/// from [`Self::Removed`] the future 3-way diff surface grows — both
1061/// trajectory items the sibling [`Semantic::ALL`] doc block already
1062/// names) reaches every projection path through exactly one caixa-
1063/// theme edit on the [`Semantic::as_str`] `pub const fn` accessor,
1064/// and the partition pin trips at test time on the first detour
1065/// that drifts a corner off.
1066///
1067/// Sixteenth and *final* peer on the substrate-wide trait-idiomatic
1068/// *borrowed-input, owned-`String` output* forward-projection family,
1069/// closing the substrate-wide 2×2-completion campaign across every
1070/// closed-set fieldless typed enum on the caixa surface — opened on
1071/// [`caixa_core::supervisor::RestartStrategy`] (579385f), extended
1072/// through [`caixa_core::supervisor::RestartPolicy`] (8465740),
1073/// [`caixa_core::dep::DepList`] (e0cb617),
1074/// [`caixa_core::CaixaKind`] (e76436d),
1075/// [`caixa_core::CaixaDialeto`] (d3c0d1d),
1076/// [`caixa_core::aplicacao::PlacementStrategy`] (d3dc000),
1077/// [`caixa_core::aplicacao::WitShape`] (d638fd3),
1078/// [`caixa_core::aplicacao::RateLimitUnit`] (6424e45 — closing the
1079/// whole M3 mesh-primitive triple's 2×2 corner),
1080/// [`caixa_core::render::PathShapeViolation`] (b90e193 — first
1081/// outside-manifest-surface arm on this axis),
1082/// [`caixa_arch::invariants::InvariantKind`] (3c3f66f — first
1083/// outside-`caixa-core` arm),
1084/// [`caixa_arch::report::ArchVerdict`] (3cfb3b5 — second outside-
1085/// `caixa-core` arm), `caixa_lint::diagnostic::Severity` (9518ab9 —
1086/// third outside-`caixa-core` arm),
1087/// `caixa_lint::diagnostic::FixSafety` (807f67d — fourth outside-
1088/// `caixa-core` arm), and `caixa_provedor::FerriteRuntime` (0caedec
1089/// — fifth outside-`caixa-core` arm), and now this lift on the
1090/// sixth-and-last outside-`caixa-core` closed-set enum — the caixa-
1091/// theme semantic-style 16-arm axis every per-Semantic paint
1092/// dispatch, every future `caixa-lsp` per-`SemanticTokenType` wire-
1093/// up, every future `caixa.nvim` per-highlight-group re-loader, and
1094/// every future `blackmatter-shell` per-arm `data-semantic="<kebab>"`
1095/// DOM emission keys off. Every future closed-set fieldless typed
1096/// enum lifted onto the caixa surface picks up the same 2×2 trait-
1097/// idiomatic projection family by construction as the substrate
1098/// discipline.
1099///
1100/// Same three-path convergence discipline as the paired owned-input
1101/// impl (this borrowed-input axis, the paired owned-input
1102/// [`From<Semantic> for String`], and [`Semantic::as_str`] all
1103/// route through the same 16-arm inline canonical-lowercase kebab
1104/// byte-strings), so a future arm addition reaches every one of the
1105/// paired forward-projection paths through exactly one caixa-theme
1106/// edit on the [`Semantic::as_str`] `pub const fn` accessor.
1107///
1108/// The [`Semantic::as_str`] emit and [`Semantic::from_wire`] parse
1109/// share the same 16 inline canonical-lowercase kebab byte-strings
1110/// by construction — so the borrowed-input owned-[`String`] forward
1111/// axis and the reverse [`TryFrom<&str>`] axis compose directly (via
1112/// the owned-[`String`]'s [`String::as_str`] borrow) without an
1113/// intermediate wire-vocab hop. The round-trip witness pin below
1114/// locks this direct composition on the caixa-theme semantic-style
1115/// enum's borrowed-input owned-[`String`] axis pair.
1116///
1117/// Pinned load-bearing by
1118/// [`tests::semantic_from_borrowed_into_owned_string_routes_through_as_str_accessor`]
1119/// (byte-parity pin against [`Semantic::as_str`] across the 16-arm
1120/// emit-set through the borrowed-input surface, plus a blanket-
1121/// derived `Into<String>` shape witness) and
1122/// [`tests::semantic_from_borrowed_into_owned_string_agrees_with_paired_axes_on_every_arm`]
1123/// (cross-axis partition pin against every one of the four 2×2
1124/// corners — the paired owned-input owned-[`String`]
1125/// [`From<Semantic> for String`] impl (5ea146c), the paired
1126/// borrowed-input owned-[`&'static str`]
1127/// [`From<&Semantic> for &'static str`] impl (ffc0f26), and the
1128/// paired owned-input owned-[`&'static str`]
1129/// [`From<Semantic> for &'static str`] impl — plus a
1130/// [`ToString::to_string`]-through-[`std::fmt::Display`] byte-parity
1131/// witness, plus a `.iter().map(String::from)` pipe witness over
1132/// [`Semantic::ALL`] (whose iterator yields `&Semantic` by
1133/// construction, so the borrowed-input owned-[`String`] axis is
1134/// what routes the pipe through the substrate-primitive
1135/// [`Semantic::as_str`] accessor without a spurious [`Copy`] deref),
1136/// plus a direct round-trip witness through [`TryFrom<&str>`] on the
1137/// owned-[`String`]'s [`String::as_str`] borrow that closes the two-
1138/// way `&Self → String → Self` round-trip on the trait-idiomatic
1139/// borrowed-input owned-[`String`] forward + reverse axis pair).
1140impl From<&Semantic> for String {
1141 fn from(sem: &Semantic) -> String {
1142 sem.as_str().to_owned()
1143 }
1144}
1145
1146/// Trait-idiomatic *owned-input* forward projection on the sixteen-arm
1147/// semantic-style [`Semantic`] closed-set fieldless typed enum onto the
1148/// [`std::borrow::Cow<'static, str>`] axis — the
1149/// [`std::borrow::Cow<'static, str>`] companion to the paired owned-
1150/// input [`From<Semantic> for &'static str`] and paired owned-input
1151/// [`From<Semantic> for String`] forward-projection corners already
1152/// lifted above. Routes through the substrate-primitive
1153/// [`Semantic::as_str`] `pub const fn` accessor via
1154/// [`std::borrow::Cow::Borrowed`] so every consumer that binds a
1155/// [`Semantic`] through the substrate's
1156/// [`std::borrow::Cow<'static, str>`] axis (a `let key:
1157/// std::borrow::Cow<'static, str> = sem.into();`-shaped downstream
1158/// call site; a future `feira lint --list-styles` operator-facing
1159/// enumeration verb whose per-style row typing binds through a
1160/// [`std::borrow::Cow<'static, str>`] boundary the sibling
1161/// `&'static str`-returning and owned-[`String`]-returning axes
1162/// force through a `std::borrow::Cow::Borrowed(sem.as_str())` /
1163/// `std::borrow::Cow::Owned(sem.to_string())` /
1164/// `String::from(sem).into()` composition; a future
1165/// `caixa-lsp`-side per-`SemanticTokenType` registration walk where
1166/// the LSP wire schema binds the kebab tag as
1167/// [`std::borrow::Cow<'static, str>`] so static semantic-style
1168/// strings avoid the runtime allocation the owned-[`String`] axis
1169/// would force; a future `caixa.nvim` per-highlight-group re-loader
1170/// whose per-Semantic kebab identifier is bound through a
1171/// [`std::borrow::Cow<'static, str>`] field so a theme-overlay row
1172/// can carry either a static kebab or a per-scheme override without
1173/// duplicating the enum-parameterized field type; a future
1174/// `blackmatter-shell` per-arm `data-semantic="<kebab>"` DOM
1175/// emission whose attribute value binds through a
1176/// [`std::borrow::Cow<'static, str>`] so the emitter can compose
1177/// static kebab strings with an occasional runtime-computed variant;
1178/// a future `HashMap::<std::borrow::Cow<'static, str>,
1179/// usize>::from_iter(Semantic::ALL.iter().copied().map(|sem|
1180/// (sem.into(), 0)))` per-Semantic-paint histogram seed on a
1181/// future per-file paint audit where the key type is
1182/// [`std::borrow::Cow<'static, str>`] rather than `&'static str` or
1183/// owned [`String`]) reaches the same 16-arm `"keyword"` /
1184/// `"symbol"` / `"keyword-arg"` / `"string"` / `"number"` /
1185/// `"literal"` / `"comment"` / `"accent"` / `"muted"` / `"error"` /
1186/// `"warning"` / `"info"` / `"hint"` / `"added"` / `"removed"` /
1187/// `"unchanged"` canonical-lowercase kebab emit-set the paired
1188/// [`std::fmt::Display`], [`AsRef<str>`], [`Semantic::as_str`], and
1189/// the four `{Self, &Self} × {&'static str, String}` 2×2 trait-
1190/// idiomatic forward-projection corners already return.
1191///
1192/// Deliberately returns [`std::borrow::Cow::Borrowed`] rather than
1193/// [`std::borrow::Cow::Owned`] — the substrate-primitive
1194/// [`Semantic::as_str`] accessor's return carries the `&'static str`
1195/// lifetime by construction (each `match` arm resolves to an inline
1196/// `&'static str` literal), so the zero-alloc borrowed arm is the
1197/// type-correct projection with no runtime allocation. Any future
1198/// silent detour that routes the impl through the
1199/// [`std::borrow::Cow::Owned`] arm (an accidental
1200/// `std::borrow::Cow::Owned(sem.to_string())` rewrite that would
1201/// allocate on every call site where the `&'static str` return of
1202/// [`Semantic::as_str`] makes the zero-alloc borrowed projection
1203/// type-correct) trips at caixa-theme test time under the
1204/// [`std::borrow::Cow::Borrowed`] discriminator witness rather than
1205/// at a downstream [`std::borrow::Cow<'static, str>`]-bound
1206/// consumer's silent allocation.
1207///
1208/// *Fifth outside-`caixa-core` peer* (and *sole peer on the caixa-
1209/// theme surface*) on the substrate-wide trait-idiomatic
1210/// [`std::borrow::Cow<'static, str>`] forward-projection family —
1211/// extends the outside-`caixa-core` tier of the campaign off the
1212/// paired caixa-lint fix-safety-tier axis on the sibling two-arm
1213/// closed-set enum ([`caixa_lint::diagnostic::FixSafety`], 79010c5 /
1214/// 9a6539f — fourth outside-`caixa-core` peer, closed the 2×3
1215/// corner) onto the semantic-style sixteen-arm axis every per-
1216/// Semantic paint dispatch, every future `caixa-lsp`
1217/// per-`SemanticTokenType` wire-up, every future `caixa.nvim`
1218/// per-highlight-group re-loader, and every future
1219/// `blackmatter-shell` per-arm `data-semantic="<kebab>"` DOM
1220/// emission dispatches through. Fourteenth peer on the axis; leaves
1221/// the remaining outside-`caixa-core` peer
1222/// (`caixa_provedor::FerriteRuntime`) as the future target. The
1223/// paired `{Self, &Self}` borrowed-input closer on `&Semantic` is
1224/// the next commit on this axis, matching the closure discipline
1225/// every prior peer landed one commit after its opener.
1226///
1227/// Rust's standard library does not carry a blanket
1228/// `impl<T: AsRef<str>> From<T> for std::borrow::Cow<'static, str>`
1229/// (nor an `impl<T: fmt::Display> From<T> for
1230/// std::borrow::Cow<'static, str>`), so every closed-set fieldless
1231/// typed enum peer on the substrate that carries the paired
1232/// [`AsRef<str>`] / [`std::fmt::Display`] / [`From<Self> for &'static
1233/// str`] / [`From<&Self> for &'static str`] / [`From<Self> for
1234/// String`] / [`From<&Self> for String`] sextet but not the
1235/// [`std::borrow::Cow<'static, str>`] axis forces every
1236/// [`std::borrow::Cow<'static, str>`]-parameterized call site
1237/// through a `std::borrow::Cow::Borrowed(sem.as_str())` /
1238/// `std::borrow::Cow::Owned(sem.to_string())` /
1239/// `String::from(sem).into()` detour whose type bounds have no
1240/// compile-time link to the substrate primitive.
1241///
1242/// The [`Semantic::as_str`] emit and [`Semantic::from_wire`] parse
1243/// share the same 16 inline canonical-lowercase kebab byte-strings
1244/// by construction — so the [`std::borrow::Cow<'static, str>`]
1245/// projection this impl exposes composes directly with the paired
1246/// trait-idiomatic reverse [`TryFrom<&str>`] axis on the
1247/// projection's [`std::borrow::Cow::as_ref`] borrow, no intermediate
1248/// wire-vocab hop required (matching the sibling
1249/// [`caixa_lint::diagnostic::FixSafety`] and
1250/// [`caixa_lint::diagnostic::Severity`] pairs — round-trip-stable —
1251/// unlike the peer [`caixa_core::CaixaKind`] pair whose forward
1252/// emit and reverse parse land on distinct vocabularies).
1253///
1254/// Pinned load-bearing by
1255/// [`tests::semantic_from_into_static_cow_str_routes_through_as_str_accessor`]
1256/// (byte-parity pin against [`Semantic::as_str`] across the sixteen-
1257/// arm emit-set through the [`std::borrow::Cow<'static, str>`]
1258/// surface, plus a [`std::borrow::Cow::Borrowed`] discriminator
1259/// witness that the projection lands on the zero-alloc arm rather
1260/// than silently allocating through [`std::borrow::Cow::Owned`],
1261/// plus a blanket-derived [`Into<std::borrow::Cow<'static, str>>`]
1262/// shape witness that also lands on [`std::borrow::Cow::Borrowed`])
1263/// and
1264/// [`tests::semantic_from_into_static_cow_str_agrees_with_paired_axes_on_every_arm`]
1265/// (cross-axis partition pin against the paired owned-input
1266/// [`From<Semantic> for &'static str`] and
1267/// [`From<Semantic> for String`] forward-projection corners plus
1268/// the sibling [`ToString::to_string`]-through-[`std::fmt::Display`]
1269/// surface, plus a `.iter().copied().map(std::borrow::Cow::from)`
1270/// pipe witness over [`Semantic::ALL`] with zero-alloc
1271/// [`std::borrow::Cow::Borrowed`] discriminator on every element,
1272/// plus a direct round-trip witness through [`TryFrom<&str>`] on
1273/// the projection's [`std::borrow::Cow::as_ref`] borrow).
1274impl From<Semantic> for std::borrow::Cow<'static, str> {
1275 fn from(sem: Semantic) -> std::borrow::Cow<'static, str> {
1276 std::borrow::Cow::Borrowed(sem.as_str())
1277 }
1278}
1279
1280/// Trait-idiomatic *borrowed-input* forward projection on the sixteen-
1281/// arm semantic-style [`Semantic`] closed-set fieldless typed enum onto
1282/// the [`std::borrow::Cow<'static, str>`] axis — the borrowed-input
1283/// companion to the paired owned-input
1284/// [`From<Semantic> for std::borrow::Cow<'static, str>`] impl (0253688)
1285/// immediately above, and the corner that closes the whole substrate-
1286/// wide `{Self, &Self} × {&'static str, String, Cow<'static, str>}`
1287/// 2×3 trait-idiomatic forward-projection family on the caixa-theme
1288/// semantic-style sixteen-arm closed-set fieldless typed enum. Routes
1289/// byte-for-byte through the substrate-primitive [`Semantic::as_str`]
1290/// `pub const fn` accessor via [`std::borrow::Cow::Borrowed`] so every
1291/// consumer that binds a `&Semantic` through the standard-library
1292/// `.into()` / [`From<&Self> for std::borrow::Cow<'static, str>`] axis
1293/// — the exact `Semantic::ALL.iter().map(std::borrow::Cow::from).collect()`
1294/// pipe shape a future `feira lint --list-styles` CLI enumeration
1295/// whose iterator yields `&Semantic` by construction, a future
1296/// `.iter().map(|tok| std::borrow::Cow::from(&tok.semantic)).collect()`
1297/// per-token fan-out over `&[SemanticToken]` in a future `caixa-lsp`-
1298/// side per-`SemanticTokenType` registration walk whose borrowed access
1299/// off `&SemanticToken.semantic` avoids a spurious [`Copy`]-bound
1300/// dereference on the semantic-style field, a future `caixa.nvim` per-
1301/// highlight-group re-loader whose per-`&Semantic` kebab identifier is
1302/// bound through a [`std::borrow::Cow<'static, str>`] field so a theme-
1303/// overlay row can carry either a static kebab or a per-scheme override
1304/// without duplicating the enum-parameterized field type, a future
1305/// `blackmatter-shell` per-arm `data-semantic="<kebab>"` DOM emission
1306/// composer over an iterator-yielded `&Semantic`, or a future
1307/// `axum::response::IntoResponse` per-semantic paint audit column over
1308/// an iterator-yielded `&Semantic` reaches — resolves to the same 16-arm
1309/// `"keyword"` / `"symbol"` / `"keyword-arg"` / `"string"` / `"number"` /
1310/// `"literal"` / `"comment"` / `"accent"` / `"muted"` / `"error"` /
1311/// `"warning"` / `"info"` / `"hint"` / `"added"` / `"removed"` /
1312/// `"unchanged"` canonical-lowercase kebab byte-strings the paired
1313/// [`std::fmt::Display`], [`AsRef<str>`], [`Semantic::as_str`], the
1314/// four `{Self, &Self} × {&'static str, String}` 2×2 trait-idiomatic
1315/// forward-projection corners, and the paired owned-input
1316/// [`From<Semantic> for std::borrow::Cow<'static, str>`] impl already
1317/// return.
1318///
1319/// Deliberately returns [`std::borrow::Cow::Borrowed`] rather than
1320/// [`std::borrow::Cow::Owned`] — the substrate-primitive
1321/// [`Semantic::as_str`] accessor's return carries the `&'static str`
1322/// lifetime by construction (each `match` arm resolves to an inline
1323/// `&'static str` literal), so the zero-alloc borrowed arm is the
1324/// type-correct projection with no runtime allocation on the borrowed-
1325/// input surface just as on the paired owned-input surface.
1326///
1327/// Closes the `{Self, &Self}` input-shape corner on the fifth outside-
1328/// `caixa-core` peer of the substrate-wide
1329/// [`std::borrow::Cow<'static, str>`] forward-projection campaign,
1330/// opened one commit prior (0253688) on the paired owned-input impl.
1331/// Rust's standard library does not carry a blanket
1332/// `impl<T: AsRef<str>> From<&T> for std::borrow::Cow<'static, str>`
1333/// (nor an `impl<T: fmt::Display> From<&T> for
1334/// std::borrow::Cow<'static, str>`, nor a [`Copy`]-based
1335/// `impl<T: Copy, U: From<T>> From<&T> for U`), so every closed-set
1336/// fieldless typed enum peer on the substrate that carries the paired
1337/// owned-input [`std::borrow::Cow<'static, str>`] axis but not the
1338/// borrowed-input axis forces every borrowed-input
1339/// [`std::borrow::Cow<'static, str>`]-parameterized call site through
1340/// a spurious [`Copy`] deref (`std::borrow::Cow::from(*sem)`) or a
1341/// `std::borrow::Cow::Borrowed(sem.as_str())` open-code whose type
1342/// bounds have no compile-time link to the substrate primitive.
1343///
1344/// Matches the closure discipline the sibling
1345/// [`caixa_lint::diagnostic::FixSafety`] (9a6539f) landed one commit
1346/// after (79010c5) closing the whole caixa-lint fix-safety-tier 2×3
1347/// corner on the fourth outside-`caixa-core` peer,
1348/// [`caixa_lint::diagnostic::Severity`] (1819087) one commit after
1349/// (700a95e) closing the whole caixa-lint diagnostic-severity 2×3
1350/// corner on the third outside-`caixa-core` peer,
1351/// [`caixa_arch::report::ArchVerdict`] (1adb287) one commit after
1352/// (b492d5f) closing the whole caixa-arch verdict-outcome 2×3 corner
1353/// on the second outside-`caixa-core` peer, d7f3039 on the sibling
1354/// caixa-arch [`caixa_arch::invariants::InvariantKind`] one commit
1355/// after (9361e96), f80fbd6 on the render-side
1356/// [`caixa_core::render::PathShapeViolation`] one commit after
1357/// (7342c32), ebeb9e0 on the outside-M3
1358/// [`caixa_core::CaixaDialeto`] one commit after 8322511, 702cdf4 on
1359/// the two-list dep-graph [`caixa_core::dep::DepList`] one commit
1360/// after 6858bac, afdf0f4 on the M3-mesh-shape
1361/// [`caixa_core::aplicacao::PlacementStrategy`] one commit after
1362/// eee504d, 25690ef on [`caixa_core::aplicacao::WitShape`] one commit
1363/// after 8634dec, 53346fb on
1364/// [`caixa_core::aplicacao::RateLimitUnit`] one commit after 1d59925
1365/// (closing the whole M3 mesh-shape tier), d45c409 on the top-level
1366/// [`caixa_core::CaixaKind`] one commit after 99c1735, and 9b3e4b3 /
1367/// ee577fd on the M2 OTP-shape
1368/// [`caixa_core::supervisor::RestartStrategy`] /
1369/// [`caixa_core::supervisor::RestartPolicy`] sibling peers one commit
1370/// after 7dd28b3 / 0612398. Closes the whole caixa-theme semantic-
1371/// style sixteen-arm 2×3 corner
1372/// (`{Self, &Self} × {&'static str, String, Cow<'static, str>}`); the
1373/// remaining outside-`caixa-core` peer (`caixa_provedor::FerriteRuntime`)
1374/// is the only future target left on the axis.
1375///
1376/// Like the sibling [`caixa_lint::diagnostic::FixSafety`] and
1377/// [`caixa_lint::diagnostic::Severity`] pairs (whose canonical-
1378/// lowercase byte-strings are round-trip-stable), and unlike the peer
1379/// [`caixa_core::CaixaKind`] pair (whose forward emit lands on the
1380/// lowercase Portuguese diagnostic vocabulary while the reverse parse
1381/// lands on the `PascalCase` wire vocabulary, forcing the round-trip
1382/// through an intermediate [`caixa_core::CaixaKind::wire_name`] hop),
1383/// [`Semantic`] is a caixa-theme semantic-style axis with no
1384/// wire/diagnostic vocabulary split — the [`Semantic::as_str`] emit
1385/// and [`Semantic::from_wire`] parse share the same sixteen inline
1386/// canonical-lowercase kebab byte-strings by construction, so the
1387/// borrowed-input [`std::borrow::Cow<'static, str>`] projection this
1388/// impl exposes composes directly with the paired trait-idiomatic
1389/// reverse [`TryFrom<&str>`] axis on the projection's
1390/// [`std::borrow::Cow::as_ref`] borrow — no intermediate wire-vocab
1391/// hop required.
1392///
1393/// Pinned load-bearing by
1394/// [`tests::semantic_from_borrowed_into_static_cow_str_routes_through_as_str_accessor`]
1395/// (byte-parity pin against [`Semantic::as_str`] across the sixteen-
1396/// arm emit-set through the borrowed-input
1397/// [`std::borrow::Cow<'static, str>`] surface, plus a
1398/// [`std::borrow::Cow::Borrowed`] discriminator witness that the
1399/// borrowed-input projection lands on the zero-alloc arm rather than
1400/// silently allocating through [`std::borrow::Cow::Owned`], plus a
1401/// blanket-derived [`Into<std::borrow::Cow<'static, str>>`] shape
1402/// witness on the borrowed-input surface that also lands on
1403/// [`std::borrow::Cow::Borrowed`]) and
1404/// [`tests::semantic_from_borrowed_into_static_cow_str_agrees_with_paired_axes_on_every_arm`]
1405/// (cross-axis partition pin against the paired owned-input
1406/// [`From<Semantic> for std::borrow::Cow<'static, str>`] impl
1407/// (0253688), the paired borrowed-input
1408/// [`From<&Semantic> for &'static str`], and
1409/// [`From<&Semantic> for String`] impls plus
1410/// [`ToString::to_string`]-through-[`std::fmt::Display`], plus a
1411/// `.iter().map(std::borrow::Cow::from)` pipe witness over
1412/// [`Semantic::ALL`] whose iterator yields `&Semantic` by construction
1413/// — so the borrowed-input axis is what routes the pipe without a
1414/// spurious [`Copy`] deref — pinning zero-alloc
1415/// [`std::borrow::Cow::Borrowed`] on every element, plus a direct
1416/// round-trip witness through [`TryFrom<&str>`] on the projection's
1417/// [`std::borrow::Cow::as_ref`] borrow that closes the two-way
1418/// `&Self → Cow<'static, str> → Self` round-trip on the borrowed-
1419/// input axis).
1420impl From<&Semantic> for std::borrow::Cow<'static, str> {
1421 fn from(sem: &Semantic) -> std::borrow::Cow<'static, str> {
1422 std::borrow::Cow::Borrowed(sem.as_str())
1423 }
1424}
1425
1426/// Trait-idiomatic *owned-input, [`Box<str>`] output* forward projection
1427/// on the caixa-theme semantic-style sixteen-arm closed-set fieldless
1428/// typed enum [`Semantic`]. Routes byte-for-byte through the substrate-
1429/// primitive [`Semantic::as_str`] `pub const fn` accessor via
1430/// [`Box::<str>::from`] on the returned `&'static str`, so every consumer
1431/// that binds a `let key: Box<str> = sem.into();`-shaped call site — a
1432/// per-semantic-style census-key materializer that stashes the
1433/// semantic-style discriminator in a [`Box<str>`]-typed heap-owned
1434/// scalar for cheap clone (a future per-semantic-style token-coloring
1435/// legend the LSP-side rich-diagnostics surface keys off), a future M4
1436/// admission-webhook rejection body whose per-arm [`Box<str>`] field
1437/// composes from an owned [`Semantic`] handle naming the accepted
1438/// semantic-style tier list, a future `feira lint --by-semantic`
1439/// histogram-column emitter that stashes each arm as an owned
1440/// [`Box<str>`] label — reaches the same sixteen canonical-lowercase
1441/// kebab byte-strings the sibling
1442/// `{Self, &Self} × {&'static str, String, Cow<'static, str>}` forward-
1443/// projection corner already returns.
1444///
1445/// Rust's standard library carries `impl From<&str> for Box<str>` and
1446/// `impl From<String> for Box<str>` but no blanket
1447/// `impl<T: AsRef<str>> From<T> for Box<str>`, so this axis is a
1448/// distinct trait-idiomatic surface that a downstream
1449/// `Semantic → Box<str>` `.into()` reaches through this impl and no
1450/// other — without a `Box::from(sem.as_str())` open-code whose type
1451/// bounds have no compile-time link back to the substrate primitive.
1452///
1453/// Extends the outside-`caixa-core` tier of the substrate-wide trait-
1454/// idiomatic [`Box<str>`] forward-projection campaign onto the fifth
1455/// peer — the caixa-theme semantic-style sixteen-arm closed-set
1456/// fieldless typed enum — following the first-mover
1457/// [`caixa_arch::invariants::InvariantKind`] pair (10613a7 owned +
1458/// 5901887 borrowed) that opened the tier, the second-peer
1459/// [`caixa_arch::report::ArchVerdict`] pair (3e08f5a owned + c4319a8
1460/// borrowed), the third-peer [`Severity`] pair (5116c95), and the
1461/// fourth-peer [`FixSafety`] pair (cf0174b) that landed one axis prior.
1462/// Same discipline as the paired
1463/// [`caixa_core::supervisor::RestartStrategy`] /
1464/// [`caixa_core::supervisor::RestartPolicy`] M2-OTP-shape and
1465/// [`caixa_core::aplicacao::PlacementStrategy`] /
1466/// [`caixa_core::aplicacao::WitShape`] /
1467/// [`caixa_core::aplicacao::RateLimitUnit`] M3-mesh-shape [`Box<str>`]
1468/// axes: forward emit (this impl, the sibling
1469/// `{&'static str, String, Cow<'static, str>}` forward-projection
1470/// corner, [`std::fmt::Display`], [`AsRef<str>`], [`Semantic::as_str`])
1471/// and reverse parse ([`Semantic::from_wire`], [`TryFrom<&str>`]) route
1472/// through the same sixteen inline canonical-lowercase kebab byte-
1473/// strings [`Semantic::as_str`] returns by construction, so the round-
1474/// trip composes directly without the wire-vocab intermediate hop the
1475/// peer [`caixa_core::CaixaKind`] axis pair requires.
1476///
1477/// Leaves the remaining outside-`caixa-core` peer
1478/// ([`caixa_provedor::FerriteRuntime`]) whose [`Box<str>`] axis closure
1479/// remains the last future target on this tier of the campaign, and
1480/// leaves the paired borrowed-input [`From<&Semantic> for Box<str>`]
1481/// `{Self, &Self}`-closer as the direct next target on this axis.
1482///
1483/// Pinned load-bearing by
1484/// [`tests::semantic_from_into_box_str_routes_through_as_str_accessor`]
1485/// (byte-parity pin against [`Semantic::as_str`] across the sixteen-
1486/// arm [`Semantic::ALL`] emit-set on the owned-input surface, plus a
1487/// blanket-derived [`Into`] shape witness).
1488impl From<Semantic> for Box<str> {
1489 fn from(sem: Semantic) -> Box<str> {
1490 Box::<str>::from(sem.as_str())
1491 }
1492}
1493
1494/// Trait-idiomatic *borrowed-input, [`Box<str>`] output* forward
1495/// projection on the caixa-theme semantic-style sixteen-arm closed-set
1496/// fieldless typed enum [`Semantic`]. Routes byte-for-byte through the
1497/// substrate-primitive [`Semantic::as_str`] `pub const fn` accessor via
1498/// [`Box::<str>::from`] on the returned `&'static str`, so every consumer
1499/// that binds a `let key: Box<str> = (&sem).into();`-shaped call site or
1500/// a `Semantic::ALL.iter().map(Box::<str>::from)`-shaped pipe (whose
1501/// iterator over `&'static [Semantic]` yields `&Semantic` by
1502/// construction) — a per-semantic-style census-key materializer that
1503/// stashes the semantic-style discriminator in a [`Box<str>`]-typed
1504/// heap-owned scalar for cheap clone off a borrowed handle, a future M4
1505/// admission-webhook rejection body whose per-arm [`Box<str>`] field
1506/// composes from a borrowed [`Semantic`] handle off a `&Semantic`
1507/// borrow, a future `feira lint --by-semantic` histogram-column emitter
1508/// that iterates [`Semantic::ALL`] into per-arm owned [`Box<str>`]
1509/// labels — reaches the same sixteen canonical-lowercase kebab byte-
1510/// strings the sibling `{Self, &Self} × {&'static str, String,
1511/// Cow<'static, str>}` forward-projection corner and the paired owned-
1512/// input [`From<Semantic> for Box<str>`] already return.
1513///
1514/// Rust's standard library carries `impl From<&str> for Box<str>` and
1515/// `impl From<String> for Box<str>` but no blanket
1516/// `impl<T: AsRef<str>> From<&T> for Box<str>` (nor a `Copy`-based
1517/// `impl<T: Copy, U: From<T>> From<&T> for U`), so this borrowed-input
1518/// axis is a distinct trait-idiomatic surface that the pipe shape
1519/// [`Semantic::ALL`]`.iter().map(Box::<str>::from)` reaches through
1520/// this impl and no other — without it, the same pipe would force an
1521/// explicit `.copied()` restatement (`.iter().copied()
1522/// .map(Box::<str>::from)`) whose type bounds have no compile-time link
1523/// back to the substrate primitive, and a `let key: Box<str> =
1524/// (&sem).into();`-shaped call site would force an explicit `Copy`
1525/// deref (`Box::<str>::from(*sem)`) or a
1526/// `Box::<str>::from(sem.as_str())` open-code with the same defect.
1527///
1528/// Closes the `{Self, &Self}` input-shape corner on the fifth outside-
1529/// `caixa-core` closed-set fieldless typed enum peer of the substrate-
1530/// wide trait-idiomatic [`Box<str>`] forward-projection campaign,
1531/// exactly as 5901887 closed the paired first-mover `InvariantKind`
1532/// axis one commit after (10613a7) landed, c4319a8 closed the paired
1533/// second-peer `ArchVerdict` axis one commit after (3e08f5a) landed,
1534/// 5116c95 landed the paired third-peer `Severity` pair one axis prior,
1535/// cf0174b landed the paired fourth-peer `FixSafety` pair one axis
1536/// prior, cb1d068 closed the paired M2-OTP-shape `RestartPolicy` axis
1537/// one commit after (0a1b313) landed, and 3c971b2 closed the paired M3-
1538/// mesh-shape `PlacementStrategy` axis one commit after (6d73e84)
1539/// landed. The remaining outside-`caixa-core` peer
1540/// ([`caixa_provedor::FerriteRuntime`]) remains the last future target
1541/// on this tier of the axis.
1542///
1543/// Same discipline as the paired
1544/// [`caixa_core::supervisor::RestartStrategy`] /
1545/// [`caixa_core::supervisor::RestartPolicy`] M2-OTP-shape and
1546/// [`caixa_core::aplicacao::PlacementStrategy`] /
1547/// [`caixa_core::aplicacao::WitShape`] /
1548/// [`caixa_core::aplicacao::RateLimitUnit`] M3-mesh-shape [`Box<str>`]
1549/// `{Self, &Self}`-closers: forward emit (this impl, the paired owned-
1550/// input [`From<Semantic> for Box<str>`] impl, the sibling
1551/// `{&'static str, String, Cow<'static, str>}` forward-projection
1552/// corner, [`std::fmt::Display`], [`AsRef<str>`], [`Semantic::as_str`])
1553/// and reverse parse ([`Semantic::from_wire`], [`TryFrom<&str>`]) route
1554/// through the same sixteen inline canonical-lowercase kebab byte-
1555/// strings [`Semantic::as_str`] returns by construction, so the round-
1556/// trip composes directly without the wire-vocab intermediate hop the
1557/// peer [`caixa_core::CaixaKind`] axis pair requires.
1558///
1559/// Pinned load-bearing by
1560/// [`tests::semantic_from_borrowed_into_box_str_routes_through_as_str_accessor`]
1561/// (byte-parity pin against [`Semantic::as_str`] across the sixteen-
1562/// arm [`Semantic::ALL`] emit-set on the borrowed-input surface, plus a
1563/// blanket-derived [`Into`] shape witness, plus a
1564/// `.iter().map(Box::<str>::from)` pipe witness over [`Semantic::ALL`]
1565/// — whose iterator yields `&Semantic` by construction, so the
1566/// borrowed-input [`Box<str>`] axis is what routes the pipe through the
1567/// substrate-primitive [`Semantic::as_str`] accessor without a spurious
1568/// [`Copy`] deref).
1569impl From<&Semantic> for Box<str> {
1570 fn from(sem: &Semantic) -> Box<str> {
1571 Box::<str>::from(sem.as_str())
1572 }
1573}
1574
1575/// Trait-idiomatic *owned-input, [`std::sync::Arc<str>`] output* forward
1576/// projection on the caixa-theme semantic-style sixteen-arm closed-set
1577/// fieldless typed enum [`Semantic`]. Opens the fifth peer of the
1578/// outside-`caixa-core` tier of the substrate-wide trait-idiomatic
1579/// [`std::sync::Arc<str>`] forward-projection campaign, following the
1580/// first-mover [`caixa_arch::invariants::InvariantKind`] pair (4e923c1
1581/// owned + 03c043f borrowed), the second-peer
1582/// [`caixa_arch::report::ArchVerdict`] pair (1682f8b owned + 92ddfb2
1583/// borrowed), the third-peer `caixa_lint::diagnostic::Severity` pair
1584/// (a7a9a6d owned + 4f041e1 borrowed), and the fourth-peer
1585/// `caixa_lint::diagnostic::FixSafety` pair (fb73edb owned + 822138e
1586/// borrowed) that landed the tier one axis prior. Routes byte-for-byte
1587/// through the substrate-primitive [`Semantic::as_str`] `pub const fn`
1588/// accessor via [`std::sync::Arc::<str>::from`] on the returned
1589/// `&'static str`.
1590///
1591/// Every consumer that binds a `let key: std::sync::Arc<str> =
1592/// sem.into();`-shaped call site — a future M4 admission-webhook
1593/// rejection body whose per-semantic-style [`std::sync::Arc<str>`] field
1594/// composes off an owned [`Semantic`] handle across an `.await` boundary
1595/// through a `<T: Into<std::sync::Arc<str>>>`-bound diagnostic-column
1596/// dispatch, a future `caixa-lsp`-side per-semantic-style materializer
1597/// stashing the semantic-style discriminator in a
1598/// [`std::sync::Arc<str>`]-typed shared-ownership scalar cloned across
1599/// concurrent tokio-scheduled `SemanticTokenType`-dispatch tasks through
1600/// [`std::sync::Arc::clone`] rather than a per-task allocation, a future
1601/// `<T: Into<std::sync::Arc<str>>>`-bound `tracing`-span attributes
1602/// collector recording an owned [`Semantic`] per-arm field onto the
1603/// parent span's shared-ownership context, a future
1604/// `feira lint --by-semantic` per-arm histogram-column emitter binding
1605/// an owned [`Semantic`] handle into a shared-ownership per-arm bucket
1606/// key across concurrent per-file lint tasks — reaches the substrate-
1607/// primitive [`Semantic::as_str`] accessor through this impl and no
1608/// other, without a `std::sync::Arc::<str>::from(sem.as_str())` open-
1609/// code whose type bounds have no compile-time link back to the
1610/// substrate primitive.
1611///
1612/// Rust's standard library carries `impl From<&str> for
1613/// std::sync::Arc<str>` and `impl From<String> for std::sync::Arc<str>`
1614/// but no blanket `impl<T: AsRef<str>> From<T> for std::sync::Arc<str>`
1615/// (nor an `impl<T: fmt::Display> From<T> for std::sync::Arc<str>`), so
1616/// this axis is a distinct trait-idiomatic surface — a two-step
1617/// `std::sync::Arc::<str>::from(String::from(sem))` composition through
1618/// the owned-`String` axis allocates twice (once into the intermediate
1619/// `String`, once into the [`std::sync::Arc<str>`] on the `From<String>`
1620/// conversion) where the single-step trait impl allocates once. The
1621/// shared-ownership + [`Sync`] + [`Send`] contract
1622/// [`std::sync::Arc<str>`] provides is the distinct value the sibling
1623/// [`Box<str>`] axis's owned-move return-shape cannot provide without a
1624/// `.clone()`-per-task materialization.
1625///
1626/// Leaves the remaining outside-`caixa-core` peer
1627/// ([`caixa_provedor::FerriteRuntime`]) as the last future target on
1628/// this tier of the campaign, and leaves the paired borrowed-input
1629/// [`From<&Semantic> for std::sync::Arc<str>`] `{Self, &Self}`-closer as
1630/// the direct next target on this same enum, mirroring the shape 03c043f
1631/// used to close the first-mover [`caixa_arch::invariants::InvariantKind`]
1632/// pair one commit after 4e923c1 opened its owned-input half, 92ddfb2
1633/// used to close the second-peer [`caixa_arch::report::ArchVerdict`]
1634/// pair one commit after 1682f8b, 4f041e1 used to close the third-peer
1635/// `caixa_lint::diagnostic::Severity` pair one commit after a7a9a6d, and
1636/// 822138e used to close the fourth-peer
1637/// `caixa_lint::diagnostic::FixSafety` pair one commit after fb73edb.
1638///
1639/// Same discipline as the paired [`From<Semantic> for Box<str>`] axis on
1640/// this same enum already opened the outside-`caixa-core` [`Box<str>`]
1641/// tier's fifth peer: forward emit (this impl, the paired sibling
1642/// `{&'static str, String, Cow<'static, str>, Box<str>}` forward-
1643/// projection corner, [`std::fmt::Display`], [`AsRef<str>`],
1644/// [`Semantic::as_str`]) and reverse parse ([`Semantic::from_wire`],
1645/// [`TryFrom<&str>`]) route through the same sixteen inline canonical-
1646/// lowercase kebab byte-strings [`Semantic::as_str`] returns by
1647/// construction, so the round-trip composes directly without the wire-
1648/// vocab intermediate hop the peer [`caixa_core::CaixaKind`] axis pair
1649/// requires.
1650///
1651/// Pinned load-bearing by
1652/// [`tests::semantic_from_into_arc_str_routes_through_as_str_accessor`]
1653/// (byte-parity pin against [`Semantic::as_str`] across the sixteen-arm
1654/// [`Semantic::ALL`] emit-set on the owned-input surface, plus a
1655/// blanket-derived [`Into`] shape witness and cross-axis byte-parity
1656/// pins against the sibling owned-input `{&'static str, String,
1657/// Cow<'static, str>, Box<str>}` return-shape axes).
1658impl From<Semantic> for std::sync::Arc<str> {
1659 fn from(sem: Semantic) -> std::sync::Arc<str> {
1660 std::sync::Arc::<str>::from(sem.as_str())
1661 }
1662}
1663
1664/// Trait-idiomatic *borrowed-input, [`std::sync::Arc<str>`] output* forward
1665/// projection on the caixa-theme semantic-style sixteen-arm closed-set
1666/// fieldless typed enum [`Semantic`]. Closes the `{Self, &Self}` input-
1667/// shape corner on the fifth peer of the outside-`caixa-core` tier of the
1668/// substrate-wide trait-idiomatic [`std::sync::Arc<str>`] forward-
1669/// projection campaign, one commit after 65dbcff opened its owned-input
1670/// half on this same enum. Routes byte-for-byte through the substrate-
1671/// primitive [`Semantic::as_str`] `pub const fn` accessor via
1672/// [`std::sync::Arc::<str>::from`] on the returned `&'static str`.
1673///
1674/// Every consumer that holds a `&Semantic` and needs a
1675/// [`std::sync::Arc<str>`] — a
1676/// `Semantic::ALL.iter().map(std::sync::Arc::<str>::from).collect::<Vec<_>>()`
1677/// per-arm semantic-style census-key materializer (whose iterator over
1678/// `&'static [Semantic]` yields `&Semantic`, not `Semantic`, so the paired
1679/// owned-input [`From<Semantic> for std::sync::Arc<str>`] axis alone
1680/// forces every call site through an explicit [`Copy`] deref or a
1681/// `.copied()` restatement rather than the direct trait-idiomatic
1682/// projection), a future M4 admission-webhook whose per-semantic-style
1683/// rejection body composes from a borrowed `&Semantic` handle across an
1684/// `.await` boundary through a `<T: Into<std::sync::Arc<str>>>`-bound
1685/// diagnostic-column dispatch, a future `caixa-lsp`-side per-semantic-
1686/// style materializer holding a shared-ownership per-arm canonical tag
1687/// from a `&Semantic` borrow through a per-file lifetime and cloning the
1688/// shared-ownership label into concurrent tokio-scheduled
1689/// `SemanticTokenType`-dispatch tasks through [`std::sync::Arc::clone`]
1690/// rather than a per-task allocation, a future
1691/// `<T: Into<std::sync::Arc<str>>>`-bound `tracing`-span attributes
1692/// collector recording a borrowed [`Semantic`] per-arm field onto the
1693/// parent span's shared-ownership context, a future
1694/// `feira lint --by-semantic` per-arm histogram-column emitter binding a
1695/// borrowed [`Semantic`] handle into a shared-ownership per-arm bucket
1696/// key across concurrent per-file lint tasks — reaches the substrate-
1697/// primitive [`Semantic::as_str`] accessor through this impl and no
1698/// other, without a `std::sync::Arc::<str>::from(sem.as_str())` open-
1699/// code whose type bounds have no compile-time link back to the
1700/// substrate primitive.
1701///
1702/// Rust's standard library carries `impl From<&str> for
1703/// std::sync::Arc<str>` and `impl From<String> for std::sync::Arc<str>`
1704/// but no blanket `impl<T: AsRef<str>> From<&T> for std::sync::Arc<str>`
1705/// (nor a `Copy`-based `impl<T: Copy, U: From<T>> From<&T> for U`), so
1706/// every closed-set fieldless typed enum peer on the substrate that
1707/// carries the paired owned-input [`std::sync::Arc<str>`] axis but not
1708/// the borrowed-input axis forces every borrowed-input
1709/// [`std::sync::Arc<str>`]-parameterized call site through a spurious
1710/// [`Copy`] deref (`std::sync::Arc::<str>::from((*sem).as_str())`) or a
1711/// `std::sync::Arc::<str>::from(sem.as_str())` open-code whose type
1712/// bounds have no compile-time link back to the substrate primitive. The
1713/// shared-ownership + [`Sync`] + [`Send`] contract [`std::sync::Arc<str>`]
1714/// provides is the distinct value the sibling [`Box<str>`] axis's owned-
1715/// move return-shape cannot provide from a borrowed-input axis without a
1716/// `.clone()`-per-task materialization.
1717///
1718/// Mirrors the exact shape 03c043f used to close the first-mover
1719/// [`caixa_arch::invariants::InvariantKind`] `{Self, &Self}` corner one
1720/// commit after 4e923c1 opened its owned-input half, 92ddfb2 used to
1721/// close the second-peer [`caixa_arch::report::ArchVerdict`] `{Self,
1722/// &Self}` corner one commit after 1682f8b, 4f041e1 used to close the
1723/// third-peer `caixa_lint::diagnostic::Severity` `{Self, &Self}` corner
1724/// one commit after a7a9a6d, and 822138e used to close the fourth-peer
1725/// `caixa_lint::diagnostic::FixSafety` `{Self, &Self}` corner one commit
1726/// after fb73edb. With this commit `Semantic` becomes the fifth outside-
1727/// `caixa-core` peer to carry the closed `{Self, &Self} × Arc<str>`
1728/// corner — the remaining outside-`caixa-core` closed-set fieldless typed
1729/// enum peer of this campaign ([`caixa_provedor::FerriteRuntime`]) now
1730/// has a five-peer `{Self, &Self}` corner template to converge onto on
1731/// the outside-`caixa-core` tier of the Arc<str> axis, hardening the
1732/// tier's shape uniformly across five peers ahead of the sixth-and-last
1733/// close.
1734///
1735/// Pinned load-bearing by
1736/// [`tests::semantic_from_borrowed_into_arc_str_routes_through_as_str_accessor`]
1737/// (byte-parity pin against [`Semantic::as_str`] across the sixteen-arm
1738/// [`Semantic::ALL`] emit-set on the borrowed-input surface, plus a
1739/// blanket-derived [`Into`] shape witness, a cross-axis partition pin
1740/// against the paired owned-input
1741/// [`From<Semantic> for std::sync::Arc<str>`] and the sibling borrowed-
1742/// input `{&'static str, String, Cow<'static, str>, Box<str>}` return-
1743/// shape axes, and a `.iter().map(std::sync::Arc::<str>::from)` pipe
1744/// witness over [`Semantic::ALL`] — whose iterator yields `&Semantic` by
1745/// construction, so the borrowed-input [`std::sync::Arc<str>`] axis is
1746/// what routes the pipe through the substrate-primitive
1747/// [`Semantic::as_str`] accessor without a spurious [`Copy`] deref).
1748impl From<&Semantic> for std::sync::Arc<str> {
1749 fn from(sem: &Semantic) -> std::sync::Arc<str> {
1750 std::sync::Arc::<str>::from(sem.as_str())
1751 }
1752}
1753
1754/// Trait-idiomatic *owned-input, [`std::rc::Rc<str>`] output* forward
1755/// projection on the caixa-theme semantic-style sixteen-arm closed-set
1756/// fieldless typed enum [`Semantic`] — the single-threaded reference-
1757/// counted peer of the paired owned-input
1758/// [`From<Semantic> for std::sync::Arc<str>`] impl immediately above on
1759/// the sibling atomically-reference-counted [`std::sync::Arc<str>`] axis.
1760/// Routes byte-for-byte through the substrate-primitive
1761/// [`Semantic::as_str`] `pub const fn` accessor via
1762/// [`std::rc::Rc::<str>::from`] on the returned `&'static str`.
1763///
1764/// Rust's standard library carries `impl From<&str> for std::rc::Rc<str>`
1765/// and `impl From<String> for std::rc::Rc<str>` but no blanket
1766/// `impl<T: AsRef<str>> From<T> for std::rc::Rc<str>` (nor a `From<&T>`
1767/// blanket), and the [`std::sync::Arc<str>`] and [`std::rc::Rc<str>`]
1768/// trait tables are disjoint, so this axis is a distinct trait-idiomatic
1769/// surface a `let key: std::rc::Rc<str> = sem.into();`-shaped call site
1770/// reaches through this impl and no other. A single-threaded caixa-theme
1771/// per-Semantic style-token renderer whose per-arm canonical-lowercase
1772/// kebab tag is cloned across intra-render tree nodes via
1773/// [`std::rc::Rc::clone`] (its cheaper non-atomic refcount bump the
1774/// [`std::sync::Arc<str>`] axis's atomically-reference-counted return-
1775/// shape cannot provide within a single-threaded theme-overlay pass), a
1776/// future `feira lint --by-semantic` single-threaded per-arm histogram-
1777/// column emitter keyed on a shared-ownership per-arm bucket key, a
1778/// future `caixa-lsp`-side per-Semantic `SemanticTokenType` panel
1779/// composer holding a shared per-arm canonical tag across intra-file
1780/// theme tree nodes without atomic contention — reaches the substrate-
1781/// primitive [`Semantic::as_str`] accessor through this impl and no
1782/// other.
1783///
1784/// Extends the outside-`caixa-core` tier of the trait-idiomatic
1785/// [`std::rc::Rc<str>`] forward-projection axis onto its fifth peer,
1786/// following the first-mover `caixa_arch::invariants::InvariantKind`
1787/// pair (c71818b `{Self, &Self}` corner) that opened the tier, second-
1788/// peer `caixa_arch::report::ArchVerdict` pair (cc759ef), third-peer
1789/// [`crate::style::Semantic`]'s caixa-lint sibling `Severity` pair
1790/// (d7c58b6), and fourth-peer `caixa_lint::diagnostic::FixSafety` pair
1791/// (046cc5f) — after the axis opened on the structurally most
1792/// fundamental caixa-core-internal [`caixa_core::CaixaKind`] pair
1793/// (e04aff0), widened onto the second caixa-core-internal peer
1794/// [`caixa_core::CaixaDialeto`] (c5595e5), extended onto the first M3-
1795/// mesh-primitive-defining slot enum
1796/// [`caixa_core::aplicacao::PlacementStrategy`] (91b4c92), and further
1797/// widened onto the render-side `PathShapeViolation` (31fc43e) and the
1798/// caixa-core-internal two-list dep-graph `DepList` (38f6a3a). Matches
1799/// the trajectory the sibling atomically-reference-counted
1800/// [`std::sync::Arc<str>`] axis walked before it onto this same enum
1801/// (the paired `impl From<Semantic> for std::sync::Arc<str>` /
1802/// `impl From<&Semantic> for std::sync::Arc<str>` pair immediately
1803/// above).
1804///
1805/// Pinned load-bearing by
1806/// [`tests::semantic_from_into_rc_str_routes_through_as_str_accessor`]
1807/// (byte-parity pin against [`Semantic::as_str`] across the sixteen-arm
1808/// [`Semantic::ALL`] emit-set on the owned-input surface, plus a
1809/// blanket-derived [`Into`] shape witness and cross-axis byte-parity
1810/// pins against the sibling owned-input `{&'static str, String,
1811/// Cow<'static, str>, Box<str>, std::sync::Arc<str>}` return-shape
1812/// axes).
1813impl From<Semantic> for std::rc::Rc<str> {
1814 fn from(sem: Semantic) -> std::rc::Rc<str> {
1815 std::rc::Rc::<str>::from(sem.as_str())
1816 }
1817}
1818
1819/// Trait-idiomatic *borrowed-input, [`std::rc::Rc<str>`] output* forward
1820/// projection on the caixa-theme semantic-style sixteen-arm closed-set
1821/// fieldless typed enum [`Semantic`] — the borrowed-input companion to
1822/// the paired owned-input [`From<Semantic> for std::rc::Rc<str>`] impl
1823/// immediately above, closing the `{Self, &Self}` input-shape corner of
1824/// the outside-`caixa-core` tier of the [`std::rc::Rc<str>`] axis on the
1825/// fifth peer. Routes byte-for-byte through the substrate-primitive
1826/// [`Semantic::as_str`] `pub const fn` accessor via
1827/// [`std::rc::Rc::<str>::from`] on the returned `&'static str`, so a
1828/// `Semantic::ALL.iter().map(std::rc::Rc::<str>::from)`-shaped pipe
1829/// (whose iterator over `&'static [Semantic]` yields `&Semantic` by
1830/// construction) reaches the same sixteen canonical-lowercase kebab
1831/// byte-strings the paired owned-input axis and the sibling `{Self,
1832/// &Self} × {&'static str, String, Cow<'static, str>, Box<str>,
1833/// std::sync::Arc<str>}` forward-projection corner already return.
1834///
1835/// Rust's standard library carries no blanket
1836/// `impl<T: AsRef<str>> From<&T> for std::rc::Rc<str>` (nor a `Copy`-
1837/// based `impl<T: Copy, U: From<T>> From<&T> for U`), so this borrowed-
1838/// input axis is a distinct trait-idiomatic surface that the pipe shape
1839/// [`Semantic::ALL`]`.iter().map(std::rc::Rc::<str>::from)` reaches
1840/// through this impl and no other — without it, the same pipe would
1841/// force a spurious [`Copy`] deref
1842/// (`std::rc::Rc::<str>::from((*sem).as_str())`) or a `.copied()`
1843/// restatement whose type bounds have no compile-time link back to the
1844/// substrate primitive.
1845///
1846/// Closes the `{Self, &Self}` input-shape corner on the fifth peer of
1847/// the outside-`caixa-core` tier of the substrate-wide trait-idiomatic
1848/// [`std::rc::Rc<str>`] forward-projection campaign, matching the
1849/// trajectory the paired [`caixa_core::CaixaKind`] (e04aff0),
1850/// [`caixa_core::CaixaDialeto`] (c5595e5),
1851/// [`caixa_core::aplicacao::PlacementStrategy`] (91b4c92),
1852/// `caixa_arch::invariants::InvariantKind` (c71818b),
1853/// `caixa_arch::report::ArchVerdict` (cc759ef),
1854/// `caixa_lint::diagnostic::Severity` (d7c58b6),
1855/// `caixa_lint::diagnostic::FixSafety` (046cc5f),
1856/// `caixa_core::render::PathShapeViolation` (31fc43e), and
1857/// `caixa_core::dep::DepList` (38f6a3a) pairs walked before it on the
1858/// caixa-core-internal, M3-mesh-primitive-defining, render-side, and
1859/// outside-`caixa-core` tiers of the same axis. Leaves the last outside-
1860/// `caixa-core` closed-set fieldless typed enum peer
1861/// ([`caixa_provedor::FerriteRuntime`]) with a nine-peer `{Self, &Self}`
1862/// corner template to converge onto, closing the outside-`caixa-core`
1863/// tier of the [`std::rc::Rc<str>`] axis on the next commit.
1864///
1865/// Pinned load-bearing by
1866/// [`tests::semantic_from_borrowed_into_rc_str_routes_through_as_str_accessor`]
1867/// (byte-parity pin against [`Semantic::as_str`] across the sixteen-arm
1868/// [`Semantic::ALL`] emit-set on the borrowed-input surface, plus a
1869/// blanket-derived [`Into`] shape witness, a cross-axis partition pin
1870/// against the paired owned-input
1871/// [`From<Semantic> for std::rc::Rc<str>`] and the sibling borrowed-
1872/// input `{&'static str, String, Cow<'static, str>, Box<str>,
1873/// std::sync::Arc<str>}` return-shape axes, and a
1874/// `.iter().map(std::rc::Rc::<str>::from)` pipe witness over
1875/// [`Semantic::ALL`] that resolves through the borrowed-input axis
1876/// without a spurious [`Copy`] deref).
1877impl From<&Semantic> for std::rc::Rc<str> {
1878 fn from(sem: &Semantic) -> std::rc::Rc<str> {
1879 std::rc::Rc::<str>::from(sem.as_str())
1880 }
1881}
1882
1883/// Trait-idiomatic *byte-view* projection on the [`Semantic`] closed-set
1884/// caixa-theme semantic-style typed enum — routes byte-for-byte through
1885/// the substrate-primitive [`Semantic::as_str`] `pub const fn` accessor's
1886/// `.as_bytes()` byte-tail so every consumer that binds a [`Semantic`]
1887/// through the standard-library `<T: AsRef<[u8]>>` trait bound (a future
1888/// [`std::io::Write::write_all`]-bound theme-preview per-token byte-sink;
1889/// a byte-keyed [`std::collections::HashMap`] `<K: AsRef<[u8]>, V>`
1890/// per-semantic-arm palette-dispatch table lookup whose entry-key trait
1891/// bound rules out the sibling [`AsRef<str>`] str-view projection; a
1892/// future `blake3::Hasher::update` / `ring::digest::Context::update` /
1893/// `sha2::Sha256::update` byte-input surface on any future per-theme
1894/// content-address digest folded into a `caixa-lsp` semantic-token
1895/// audit closure) reaches the substrate primitive through one trait
1896/// dispatch rather than open-coding the two-hop `sem.as_str().as_bytes()`
1897/// composition at every call site.
1898///
1899/// Rust's standard library carries `impl AsRef<[u8]> for str` and
1900/// `impl AsRef<[u8]> for String`, so the two-hop composition
1901/// `sem.as_str().as_bytes()` is reachable through the pre-existing
1902/// str-view axis alone. But that two-hop shape has no compile-time link
1903/// back to the byte-projection axis, forces every downstream
1904/// `<T: AsRef<[u8]>>`-bound consumer to open-code the composition at
1905/// every call site, and admits a silent split whenever a future call
1906/// site takes a sibling reverse-projection axis whose `.as_bytes()`
1907/// byte-tail carries no compile-time byte-view surface. The lifted
1908/// single-hop impl closes the byte-view axis so every future
1909/// `<T: AsRef<[u8]>>`-bound consumer reaches the substrate primitive
1910/// through one trait dispatch, and every future arm addition (a
1911/// `Namespace` tier between [`Semantic::Symbol`] and
1912/// [`Semantic::KeywordArg`] for the M4 tatara-lisp module system's
1913/// qualified-name semantic-token dispatch, a `Deleted` tier for a
1914/// hard-delete-mark distinct from [`Semantic::Removed`] the future
1915/// 3-way diff surface grows — both trajectory items the sibling
1916/// [`Semantic::ALL`] doc block already names) grows the byte-view axis
1917/// through one edit on the substrate-primitive [`Semantic::as_str`]
1918/// accessor.
1919///
1920/// Extends the substrate-wide trait-idiomatic byte-view axis onto the
1921/// *fifth outside-caixa-core* closed-set fieldless typed enum on the
1922/// caixa surface — matching the trajectory the caixa-core-internal
1923/// [`caixa_core::CaixaKind`] first-mover impl (69d8d86),
1924/// [`caixa_core::CaixaDialeto`] second-mover impl (8151347),
1925/// [`caixa_core::dep::DepList`] third-mover impl (05ffaca), the
1926/// M3-mesh-primitive-defining
1927/// [`caixa_core::aplicacao::PlacementStrategy`] impl (daa8705),
1928/// [`caixa_core::aplicacao::RateLimitUnit`] impl (4867e0f), the first-
1929/// mover outside-caixa-core [`caixa_arch::invariants::InvariantKind`]
1930/// impl (b5baf7d), the second-mover outside-caixa-core
1931/// [`caixa_arch::report::ArchVerdict`] impl (0e0057a), the third-mover
1932/// outside-caixa-core `caixa_lint::Severity` impl (1e65136), and the
1933/// fourth-mover outside-caixa-core `caixa_lint::FixSafety` impl
1934/// (1da1afc) walked before it, plus the M2-OTP-shape
1935/// [`caixa_core::supervisor::RestartStrategy`] (cd4c4e0) +
1936/// [`caixa_core::supervisor::RestartPolicy`] (98b08fa), the
1937/// M3-mesh-contratos [`caixa_core::aplicacao::WitShape`] (0e2d0f2), and
1938/// the render-side [`caixa_core::render::PathShapeViolation`] (2c58220)
1939/// peers. The paired [`Semantic::as_str`] accessor returns the canonical
1940/// lowercase-kebab wire byte-string (`"keyword"` / `"symbol"` /
1941/// `"keyword-arg"` / `"string"` / `"number"` / `"literal"` / `"comment"`
1942/// / `"accent"` / `"muted"` / `"error"` / `"warning"` / `"info"` /
1943/// `"hint"` / `"added"` / `"removed"` / `"unchanged"`) every
1944/// `blackmatter-shell` `data-semantic="<kebab>"` DOM emit site, every
1945/// `caixa-lsp`-side per-`SemanticTokenType` registration, every
1946/// `feira lint --list-styles` per-arm enumeration, and every future M4
1947/// theme-overlay re-loader keys off. Leaves the last outside-`caixa-core`
1948/// closed-set fieldless typed-enum peer ([`caixa_provedor::FerriteRuntime`])
1949/// as the campaign's next mechanical one-impl extension against the
1950/// substrate-primitive `as_str` accessor it already carries.
1951///
1952/// Pinned load-bearing by
1953/// [`tests::semantic_as_ref_bytes_routes_through_as_str_accessor`]
1954/// (fail-before-pass-after byte-parity pin against [`Semantic::as_str`]
1955/// `.as_bytes()` across the sixteen-arm [`Semantic::ALL`] emit-set,
1956/// cross-axis witness against the paired str-view [`AsRef<str>`] /
1957/// [`std::fmt::Display`] / [`Semantic::as_str`] axes' `.as_bytes()`
1958/// byte-tails, cross-axis witness against the paired reverse-projection
1959/// `{&'static str, String, Cow<'static, str>, Box<str>,
1960/// std::sync::Arc<str>, std::rc::Rc<str>}` return-shape axes'
1961/// `.as_bytes()` byte-tails, a `<T: AsRef<[u8]>>`-bound-consumer witness
1962/// on both owned and borrowed input surfaces, and a
1963/// `blake3::Hasher::update`-shape byte-input surface witness routed
1964/// through the `<T: AsRef<[u8]>>`-bound consumer axis to reach the
1965/// caixa-lacre compounding target).
1966impl AsRef<[u8]> for Semantic {
1967 fn as_ref(&self) -> &[u8] {
1968 self.as_str().as_bytes()
1969 }
1970}
1971
1972/// Trait-idiomatic *owned-input, owned-`Vec<u8>` output* byte-owned reverse
1973/// projection on the [`Semantic`] closed-set caixa-theme semantic-style typed
1974/// enum — routes byte-for-byte through the substrate-primitive
1975/// [`Semantic::as_str`] `pub const fn` accessor via [`str::as_bytes`] +
1976/// [`slice::to_vec`] so every consumer that binds a [`Semantic`] through the
1977/// standard-library `<T: Into<Vec<u8>>>` trait bound (a future
1978/// [`std::io::Write::write_all`]-shape per-theme audit-log byte-sink whose
1979/// input parameter is an owned [`Vec<u8>`] payload, a future
1980/// `bytes::Bytes::from(Vec::<u8>::from(semantic))` composer folding the
1981/// per-arm byte-tag into the [`bytes::Bytes`] framing surface, a future
1982/// `hasher.update(&Vec::<u8>::from(semantic))`-shape BLAKE3 per-theme
1983/// content-address closure that needs the owned byte-tail buffered before
1984/// folding into the [`caixa_lacre::Lacre`] closure body) reaches the same
1985/// sixteen-arm canonical-lowercase kebab byte-string emit-set the paired
1986/// [`AsRef<[u8]>`] borrowed byte-view axis (2c58220) and the six str-owned
1987/// reverse-projection corners already return, rather than an open-coded
1988/// per-call-site `semantic.as_str().as_bytes().to_vec()` composition whose
1989/// type bounds have no compile-time link back to the substrate primitive.
1990///
1991/// Extends the substrate-wide trait-idiomatic byte-owned reverse-projection
1992/// axis onto the *fifth outside-`caixa-core`* closed-set fieldless typed-enum
1993/// peer — matching the trajectory the caixa-core-internal
1994/// [`caixa_core::CaixaKind`] first-mover (b245fd6),
1995/// [`caixa_core::CaixaDialeto`] (4cceaf5),
1996/// [`caixa_core::dep::DepList`] (e974ca2), the M2-OTP-shape
1997/// [`caixa_core::supervisor::RestartStrategy`] (63e5dd0) /
1998/// [`caixa_core::supervisor::RestartPolicy`] (96a522a),
1999/// the M3-mesh-primitive-defining
2000/// [`caixa_core::aplicacao::PlacementStrategy`] (008a35b) /
2001/// [`caixa_core::aplicacao::RateLimitUnit`] (602ae0b) /
2002/// [`caixa_core::aplicacao::WitShape`] (7b4b278), the outside-`caixa-core`
2003/// first-mover `caixa_arch::invariants::InvariantKind` (ed29f5a), the
2004/// second-mover `caixa_arch::report::ArchVerdict` (5268ed1), the third-mover
2005/// `caixa_lint::Severity` (3aa6644), the fourth-mover `caixa_lint::FixSafety`
2006/// (38060a4), and the render-side [`caixa_core::render::PathShapeViolation`]
2007/// (c98fb87) peers walked before it. Leaves the last outside-`caixa-core`
2008/// closed-set fieldless typed-enum peer ([`caixa_provedor::FerriteRuntime`])
2009/// as the campaign's next mechanical one-lift extension against the
2010/// substrate-primitive `as_str` accessor it already carries — tracking the
2011/// paired byte-view axis's outside-`caixa-core` sweep verbatim.
2012///
2013/// Pinned load-bearing by
2014/// [`tests::semantic_from_into_owned_vec_bytes_routes_through_as_str_accessor`]
2015/// (byte-parity pin against [`Semantic::as_str`] across the sixteen-arm
2016/// [`Semantic::ALL`] emit-set binding the byte-owned reverse-projection axis
2017/// against the paired [`AsRef<[u8]>`] borrowed byte-view axis and the
2018/// str-owned reverse-projection family's `.into_bytes()` /
2019/// `.as_bytes().to_vec()` byte-tails, plus a `<T: Into<Vec<u8>>>`-bound
2020/// generic-consumer witness on both owned and borrowed input shapes).
2021impl From<Semantic> for Vec<u8> {
2022 fn from(semantic: Semantic) -> Vec<u8> {
2023 semantic.as_str().as_bytes().to_vec()
2024 }
2025}
2026
2027/// Trait-idiomatic *borrowed-input, owned-`Vec<u8>` output* byte-owned reverse
2028/// projection on [`Semantic`] — the borrowed-input peer of
2029/// [`From<Semantic> for Vec<u8>`], closing the `{Self, &Self} → Vec<u8>` pair
2030/// on the byte-owned reverse-projection axis in one lift. Routes byte-for-byte
2031/// through the substrate-primitive [`Semantic::as_str`] `pub const fn`
2032/// accessor so every consumer that holds a borrowed [`&Semantic`] and needs
2033/// an owned [`Vec<u8>`] — a future `.iter().map(Vec::<u8>::from).collect()`
2034/// pipe over `&[Semantic]` (whose iterator yields `&Semantic`, not
2035/// `Semantic`, so the owned-input axis alone forces every call site through
2036/// an explicit `.copied()` restatement rather than the direct
2037/// trait-idiomatic projection), a future `feira lint --list-styles` byte
2038/// emitter walking [`Semantic::ALL`] through an `Into<Vec<u8>>`-bound
2039/// per-arm byte-writer to surface the accepted semantic-style tag set —
2040/// reaches the same sixteen-arm canonical-lowercase kebab byte-string
2041/// emit-set the paired owned-input peer already returns.
2042impl From<&Semantic> for Vec<u8> {
2043 fn from(semantic: &Semantic) -> Vec<u8> {
2044 semantic.as_str().as_bytes().to_vec()
2045 }
2046}
2047
2048/// Trait-idiomatic *borrowed byte-slice* reverse projection on the
2049/// [`Semantic`] closed-set caixa-theme semantic-style typed enum —
2050/// routes byte-for-byte through [`std::str::from_utf8`] +
2051/// the substrate-primitive [`Semantic::from_wire`] `Option<Self>`
2052/// accessor, so `<Semantic as TryFrom<&[u8]>>::try_from(bytes)`
2053/// reaches the same sixteen-arm canonical-lowercase-kebab wire-form
2054/// accept-set the sibling method-named [`Semantic::from_wire`]
2055/// resolver and the paired [`TryFrom<&str>`] impl already resolve
2056/// against. Both rejection paths (invalid UTF-8 and valid-UTF-8-but-
2057/// unknown-wire) collapse onto the single unit-error `Err(())`
2058/// return, matching the trait-idiomatic-`()`-error shape the
2059/// substrate-wide sibling `TryFrom<&[u8]>` impls carry.
2060///
2061/// Extends the substrate-wide trait-idiomatic byte-view reverse-
2062/// projection axis onto the *fifth* outside-`caixa-core` closed-set
2063/// fieldless typed-enum peer (and the first inside `caixa-theme`):
2064/// the sixteen-arm caixa-theme semantic-style accept-set every
2065/// per-`Semantic` paint dispatch, every future `caixa-lsp`-side
2066/// per-`SemanticTokenType` wire-up, every future `caixa.nvim` per-
2067/// highlight-group re-loader, and every future `blackmatter-shell`
2068/// per-arm `data-semantic="<kebab>"` DOM-attribute re-loader
2069/// dispatches through — matching the trajectory the first-mover
2070/// outside-`caixa-core` [`caixa_arch::invariants::InvariantKind`]
2071/// `TryFrom<&[u8]>` impl (40b7417), second-mover outside-`caixa-core`
2072/// [`caixa_arch::report::ArchVerdict`] `TryFrom<&[u8]>` impl
2073/// (4dbca85), third-mover outside-`caixa-core`
2074/// `caixa_lint::diagnostic::Severity` `TryFrom<&[u8]>` impl (f11dc96),
2075/// and fourth-mover outside-`caixa-core`
2076/// `caixa_lint::diagnostic::FixSafety` `TryFrom<&[u8]>` impl
2077/// (46a3e3e) walked before it. Leaves the last outside-`caixa-core`
2078/// closed-set fieldless typed-enum peer
2079/// ([`caixa_provedor::FerriteRuntime`]) as the campaign's next
2080/// mechanical one-lift extension — tracking the paired byte-owned
2081/// axis's outside-`caixa-core` sweep verbatim.
2082///
2083/// Pinned load-bearing by
2084/// [`tests::semantic_try_from_bytes_routes_through_from_wire_accessor`]
2085/// (byte-parity pin against [`Semantic::from_wire`] across the
2086/// sixteen-arm [`Semantic::ALL`] accept-set on the borrowed byte-
2087/// slice surface, plus a cross-axis witness that the byte-view
2088/// reverse projection agrees with the paired [`TryFrom<&str>`] str-
2089/// view reverse axis on every accepted arm, and a forward/reverse
2090/// byte-view cross-axis witness that feeding the paired
2091/// [`AsRef<[u8]>`] byte-tail and the paired
2092/// [`From<Semantic> for Vec<u8>`] and [`From<&Semantic> for Vec<u8>`]
2093/// owned byte-tails back through the new impl round-trips to the
2094/// originating arm) and
2095/// [`tests::semantic_try_from_bytes_rejects_unknown_and_non_utf8_bytes`]
2096/// (rejection witness against silent accept-set widening on both the
2097/// non-UTF-8 byte-sequence rejection path and the unknown-wire-
2098/// vocabulary rejection path — the latter mirrors the corpus the
2099/// paired [`TryFrom<&str>`] rejection witness already pins, including
2100/// the trajectory-item candidates `b"namespace"` / `b"deleted"` the
2101/// sibling [`Semantic::ALL`] doc block already names and sibling
2102/// closed-set canonical tags on other axes so a byte-level cross-
2103/// axis leak trips at caixa-theme test time rather than at a
2104/// downstream consumer's silent misclassification).
2105impl TryFrom<&[u8]> for Semantic {
2106 type Error = ();
2107
2108 fn try_from(bytes: &[u8]) -> Result<Self, <Self as TryFrom<&[u8]>>::Error> {
2109 std::str::from_utf8(bytes)
2110 .ok()
2111 .and_then(Self::from_wire)
2112 .ok_or(())
2113 }
2114}
2115
2116#[cfg(test)]
2117mod tests {
2118 use super::*;
2119
2120 #[test]
2121 fn semantic_all_enumerates_every_variant_in_declaration_order() {
2122 // Fail-before-pass-after pin on the [`Semantic::ALL`] slice:
2123 // the slice must list every one of the 15 variants in
2124 // declaration order (Keyword → Symbol → KeywordArg → String →
2125 // Number → Literal → Comment → Accent → Muted → Error →
2126 // Warning → Info → Hint → Added → Removed → Unchanged). Peer
2127 // of the sibling ALL slices on the closed-set typed-enum
2128 // discriminator axes ([`caixa_core::CaixaKind::ALL`],
2129 // [`caixa_core::supervisor::RestartStrategy::ALL`],
2130 // [`caixa_core::supervisor::RestartPolicy::ALL`],
2131 // [`caixa_core::aplicacao::PlacementStrategy::ALL`],
2132 // [`caixa_core::upgrade::UpgradeInstruction::ALL`]). A future
2133 // arm addition (a `Namespace` tier between `Symbol` and
2134 // `KeywordArg` for the M4 tatara-lisp module system's
2135 // qualified-name semantic-token dispatch, a `Deleted` tier
2136 // for a hard-delete-mark distinct from `Removed` the future
2137 // 3-way diff surface grows) that lands the arm on the enum
2138 // but forgets to extend `ALL` must trip this pin rather than
2139 // surface as a downstream consumer's silently-partial
2140 // iteration.
2141 assert_eq!(
2142 Semantic::ALL,
2143 &[
2144 Semantic::Keyword,
2145 Semantic::Symbol,
2146 Semantic::KeywordArg,
2147 Semantic::String,
2148 Semantic::Number,
2149 Semantic::Literal,
2150 Semantic::Comment,
2151 Semantic::Accent,
2152 Semantic::Muted,
2153 Semantic::Error,
2154 Semantic::Warning,
2155 Semantic::Info,
2156 Semantic::Hint,
2157 Semantic::Added,
2158 Semantic::Removed,
2159 Semantic::Unchanged,
2160 ],
2161 );
2162 // Also pin the per-arm `IsVariant`-derived partition: every
2163 // arm in `ALL` must satisfy exactly one of the 15 generated
2164 // arm-discriminator predicates.
2165 for variant in Semantic::ALL {
2166 let row = [
2167 variant.is_keyword(),
2168 variant.is_symbol(),
2169 variant.is_keyword_arg(),
2170 variant.is_string(),
2171 variant.is_number(),
2172 variant.is_literal(),
2173 variant.is_comment(),
2174 variant.is_accent(),
2175 variant.is_muted(),
2176 variant.is_error(),
2177 variant.is_warning(),
2178 variant.is_info(),
2179 variant.is_hint(),
2180 variant.is_added(),
2181 variant.is_removed(),
2182 variant.is_unchanged(),
2183 ];
2184 let hits = row.iter().filter(|b| **b).count();
2185 assert_eq!(
2186 hits, 1,
2187 "Semantic::{variant:?} must satisfy exactly one of the \
2188 15 is_* arm-discriminator predicates; got {row:?}",
2189 );
2190 }
2191 }
2192
2193 #[test]
2194 fn semantic_is_variant_predicates_partition_the_arm_set() {
2195 // Fail-before-pass-after pin on the [`gen_platform::IsVariant`]
2196 // derive: for each of the 15 variants, exactly one of the
2197 // generated is_* predicates returns `true` and the other 14
2198 // return `false`. Pre-derive the closed 15-arm partition
2199 // lived only inside the two theme overlays' 15-arm match
2200 // resolvers; a future rebrand (a `#[is_variant(name = "…")]`
2201 // drift, a manual hand-rolled `impl` that shadows the
2202 // derive-generated method, an arm rename) trips this pin at
2203 // caixa-theme build time rather than surfacing far from the
2204 // derive declaration. Peer of the sibling
2205 // [`caixa_core::CaixaKind`] `IsVariant` partition pin.
2206 // A copy-paste flip that reroutes one arm through the wrong
2207 // predicate lane trips at the identity-diagonal assertion,
2208 // since each variant's row is generated live from `ALL`'s
2209 // declaration order rather than transcribed by hand.
2210 for (idx, variant) in Semantic::ALL.iter().enumerate() {
2211 let observed: [bool; 16] = [
2212 variant.is_keyword(),
2213 variant.is_symbol(),
2214 variant.is_keyword_arg(),
2215 variant.is_string(),
2216 variant.is_number(),
2217 variant.is_literal(),
2218 variant.is_comment(),
2219 variant.is_accent(),
2220 variant.is_muted(),
2221 variant.is_error(),
2222 variant.is_warning(),
2223 variant.is_info(),
2224 variant.is_hint(),
2225 variant.is_added(),
2226 variant.is_removed(),
2227 variant.is_unchanged(),
2228 ];
2229 let mut expected = [false; 16];
2230 expected[idx] = true;
2231 assert_eq!(
2232 observed, expected,
2233 "Semantic::{variant:?} at ALL[{idx}] is_* predicates \
2234 must fire only on their own arm lane (identity \
2235 diagonal); got {observed:?}",
2236 );
2237 }
2238 }
2239
2240 #[test]
2241 fn semantic_as_str_returns_canonical_kebab_case_per_arm() {
2242 // Fail-before-pass-after per-arm byte-string pin on
2243 // [`Semantic::as_str`] — the substrate-canonical `&'static str`
2244 // projection every downstream consumer of the closed 16-arm
2245 // partition reaches through. A future arm rename (a `Symbol` →
2246 // `Identifier` rebrand tracking a hypothetical LSP-side
2247 // `SemanticTokenType` reshuffle, an `Accent` → `Highlight`
2248 // rebrand tracking a `blackmatter-shell` classname rework) that
2249 // touches the enum arm but forgets to update the paired
2250 // `as_str` arm — or vice versa — trips this pin at caixa-theme
2251 // build time rather than surfacing as a downstream
2252 // `feira lint --list-styles` operator-facing enumeration verb's
2253 // silently-renamed row far from the two-declaration site.
2254 //
2255 // Kebab-case matches the peer [`gen_platform::IsVariant`]-
2256 // derived kebab discriminant convention the sibling closed-set
2257 // typed enums already emit on their canonical byte-string
2258 // projection axis.
2259 assert_eq!(Semantic::Keyword.as_str(), "keyword");
2260 assert_eq!(Semantic::Symbol.as_str(), "symbol");
2261 assert_eq!(Semantic::KeywordArg.as_str(), "keyword-arg");
2262 assert_eq!(Semantic::String.as_str(), "string");
2263 assert_eq!(Semantic::Number.as_str(), "number");
2264 assert_eq!(Semantic::Literal.as_str(), "literal");
2265 assert_eq!(Semantic::Comment.as_str(), "comment");
2266 assert_eq!(Semantic::Accent.as_str(), "accent");
2267 assert_eq!(Semantic::Muted.as_str(), "muted");
2268 assert_eq!(Semantic::Error.as_str(), "error");
2269 assert_eq!(Semantic::Warning.as_str(), "warning");
2270 assert_eq!(Semantic::Info.as_str(), "info");
2271 assert_eq!(Semantic::Hint.as_str(), "hint");
2272 assert_eq!(Semantic::Added.as_str(), "added");
2273 assert_eq!(Semantic::Removed.as_str(), "removed");
2274 assert_eq!(Semantic::Unchanged.as_str(), "unchanged");
2275 }
2276
2277 #[test]
2278 fn semantic_as_str_projections_are_all_distinct_across_arms() {
2279 // Fail-before-pass-after pin on the injectivity of
2280 // [`Semantic::as_str`]'s projection — no two arms may share
2281 // their canonical kebab byte-string, since a future consumer
2282 // that keys a per-arm dispatch table off the projection (a
2283 // `HashMap::<&str, _>::from_iter(Semantic::ALL.iter().map(|s|
2284 // (s.as_str(), …)))` style-lookup, a future `caixa-lsp`
2285 // `SemanticTokenType::new(sem.as_ref())` registration table
2286 // keyed by kebab identifier, a future `feira lint --list-styles`
2287 // one-row-per-arm enumeration table) would silently collapse
2288 // the two colliding arms onto one entry, dropping the second
2289 // insertion. A future arm addition (a `Namespace` tier between
2290 // `Symbol` and `KeywordArg` for the M4 tatara-lisp module
2291 // system's qualified-name semantic-token dispatch, a `Deleted`
2292 // tier for a hard-delete-mark distinct from `Removed` a future
2293 // 3-way diff surface grows) that lands the arm on the enum and
2294 // reuses a peer arm's kebab identifier (a copy-paste-derived
2295 // `"removed"` on the new `Deleted` arm) trips this pin rather
2296 // than surfacing far from the arm addition site.
2297 let mut projections: Vec<&'static str> = Semantic::ALL.iter().map(|s| s.as_str()).collect();
2298 let before = projections.len();
2299 projections.sort_unstable();
2300 projections.dedup();
2301 assert_eq!(
2302 projections.len(),
2303 before,
2304 "Semantic::as_str must be injective across ALL — collisions: \
2305 {projections:?}",
2306 );
2307 }
2308
2309 #[test]
2310 fn semantic_display_and_as_ref_str_route_through_as_str_accessor() {
2311 // Fail-before-pass-after three-path convergence pin on the
2312 // substrate-wide `(as_str, AsRef<str>, Display)` canonical-
2313 // projection triple for the caixa-theme [`Semantic`] closed-set
2314 // fieldless typed enum. For every arm in [`Semantic::ALL`], the
2315 // paired [`std::fmt::Display`] impl + [`AsRef<str>`] impl + the
2316 // substrate-canonical [`Semantic::as_str`] `pub const fn`
2317 // scalar accessor must resolve to the same `&'static str`
2318 // per arm. Peer of the sibling three-path-convergence pins the
2319 // substrate carries on the closed-set typed enums the prior
2320 // lifts converged onto
2321 // (`restart_strategy_display_routes_through_as_str_helper` /
2322 // `restart_strategy_as_ref_str_routes_through_as_str_accessor`
2323 // on [`caixa_core::supervisor::RestartStrategy`],
2324 // `ferrite_runtime_display_and_as_ref_str_route_through_variant_slug_accessor`
2325 // on `caixa_provedor::FerriteRuntime`, and the analogous pins
2326 // on `caixa_lint::Severity` / `caixa_lint::FixSafety` /
2327 // `caixa_arch::InvariantKind` / `caixa_arch::ArchVerdict`).
2328 //
2329 // A future accidental split (a hand-rolled `impl fmt::Display`
2330 // that shadows this route through a divergent per-arm match, an
2331 // `impl AsRef<str>` that returns the compiler-derived `Debug`
2332 // string via `format!("{:?}", self)` — allocating and diverging
2333 // on every arm — or a `#[serde(rename_all = "…")]` attribute
2334 // drift that quietly forks the projection) trips this pin at
2335 // caixa-theme build time rather than surfacing as a downstream
2336 // consumer's silently-forked per-Semantic dispatch far from the
2337 // trait-impl declaration site.
2338 for &sem in Semantic::ALL {
2339 let via_as_str: &str = sem.as_str();
2340 let via_display: String = format!("{sem}");
2341 let via_as_ref: &str = <Semantic as AsRef<str>>::as_ref(&sem);
2342 assert_eq!(
2343 via_display, via_as_str,
2344 "Semantic::{sem:?} — Display routes off `as_str`; got \
2345 Display={via_display:?} vs as_str={via_as_str:?}",
2346 );
2347 assert_eq!(
2348 via_as_ref, via_as_str,
2349 "Semantic::{sem:?} — AsRef<str> routes off `as_str`; got \
2350 AsRef={via_as_ref:?} vs as_str={via_as_str:?}",
2351 );
2352 }
2353 }
2354
2355 #[test]
2356 fn semantic_as_str_is_usable_in_const_context() {
2357 // The [`Semantic::as_str`] accessor is declared `pub const fn`,
2358 // matching the peer closed-set typed enums' canonical
2359 // `&'static str` projection accessors
2360 // ([`caixa_core::CaixaKind::as_str`],
2361 // [`caixa_core::supervisor::RestartStrategy::as_str`],
2362 // [`caixa_core::aplicacao::PlacementStrategy::as_str`],
2363 // `caixa_provedor::FerriteRuntime::variant_slug`). Pin the
2364 // same posture with a `const {}` assertion block so a future
2365 // accidental downgrade to non-`const` (an added runtime helper
2366 // reachable only from a non-`const` context) trips at
2367 // caixa-theme build time rather than surfacing as a downstream
2368 // `const`-context regression far from the accessor
2369 // declaration.
2370 const KEYWORD: &str = Semantic::Keyword.as_str();
2371 const ERROR: &str = Semantic::Error.as_str();
2372 const UNCHANGED: &str = Semantic::Unchanged.as_str();
2373 const { assert!(KEYWORD.as_bytes()[0] == b'k') };
2374 const { assert!(ERROR.as_bytes()[0] == b'e') };
2375 const { assert!(UNCHANGED.as_bytes()[0] == b'u') };
2376 }
2377
2378 #[test]
2379 fn semantic_from_wire_accepts_every_as_str_output() {
2380 // Fail-before-pass-after per-arm accept pin on the newly lifted
2381 // [`Semantic::from_wire`] reverse projection: every arm in
2382 // [`Semantic::ALL`] must parse back through `from_wire` when fed
2383 // its own [`Semantic::as_str`] output, landing on
2384 // `Some(same_variant)`. A regression that hand-rolled either
2385 // side's per-arm match without threading through the shared
2386 // 16-string closed set would silently disagree on any future
2387 // arm rename (a `Symbol` → `Identifier` rebrand tracking a
2388 // hypothetical LSP-side `SemanticTokenType` reshuffle, an
2389 // `Accent` → `Highlight` rebrand tracking a `blackmatter-shell`
2390 // classname rework) or new arm the theme grows (a `Namespace`
2391 // tier between `Symbol` and `KeywordArg` for the M4 tatara-lisp
2392 // module system's qualified-name semantic-token dispatch, a
2393 // `Deleted` tier for a hard-delete-mark distinct from `Removed`
2394 // the future 3-way diff surface grows) and this pin flags it at
2395 // caixa-theme build time rather than at a downstream
2396 // `feira lint --list-styles` operator-facing enumeration verb's
2397 // silent tag misclassification.
2398 //
2399 // Peer of the sibling
2400 // `caixa_lint::diagnostic::tests::severity_from_wire_accepts_every_as_str_output`
2401 // (5afff0e) /
2402 // `caixa_lint::diagnostic::tests::fix_safety_from_wire_accepts_every_as_str_output`
2403 // (bd505a1) /
2404 // `caixa_arch::report::tests::arch_verdict_from_wire_accepts_every_as_str_output`
2405 // (6afe564) /
2406 // `caixa_arch::invariants::tests::invariant_kind_from_wire_accepts_every_as_str_output`
2407 // (b9e4e61) round-trip pins on the peer caixa-lint / caixa-arch
2408 // closed-set-enum reverse-projection axes, and of the sibling
2409 // `caixa_core::kind::tests::caixa_kind_wire_round_trips_through_from_wire`
2410 // (2aa6d23) /
2411 // `caixa_core::dialeto::tests::caixa_dialeto_from_wire_accepts_every_as_str_output`
2412 // (d0e65ea) /
2413 // `caixa_core::aplicacao::tests::placement_strategy_from_wire_accepts_every_lifted_constant`
2414 // (18c7342) /
2415 // `caixa_core::dep::tests::dep_list_round_trips_through_as_str_and_from_wire`
2416 // (45ee563) /
2417 // `caixa_core::render::tests::path_shape_violation_from_wire_accepts_every_as_str_output`
2418 // (aebd9c6) round-trip pins on the sibling caixa-core closed-
2419 // set typed-enum reverse-projection axes.
2420 for &variant in Semantic::ALL {
2421 let wire = variant.as_str();
2422 let parsed = Semantic::from_wire(wire).unwrap_or_else(|| {
2423 panic!(
2424 "Semantic::from_wire({wire:?}) must accept every \
2425 Semantic::as_str output — got None for the wire \
2426 byte-string of {variant:?}"
2427 )
2428 });
2429 assert_eq!(
2430 parsed, variant,
2431 "Semantic::from_wire(Semantic::{variant:?}.as_str()) \
2432 must return Semantic::{variant:?} — the (as_str, \
2433 from_wire) pair must form a total round-trip on the \
2434 closed 16-arm Semantic arm-set",
2435 );
2436 }
2437 }
2438
2439 #[test]
2440 fn semantic_from_wire_rejects_unknown_byte_strings() {
2441 // Rejection pin on the [`Semantic::from_wire`] parser's accept-
2442 // set: any string outside the 16-arm [`Semantic::as_str`] output
2443 // set must return `None`. A future accidental widening of the
2444 // accept-set (a case-insensitive match that accepts `"KEYWORD"`
2445 // / `"Keyword"`, a silent acceptance of the pre-lift PascalCase
2446 // Debug-derived shapes `"Keyword"` / `"KeywordArg"` /
2447 // `"Unchanged"` on the wire axis, a snake_case drift accepting
2448 // `"keyword_arg"` beside the canonical kebab-case
2449 // `"keyword-arg"`, a Levenshtein-forgiving arm-lookup that
2450 // admits `"kewyord"` typos, a silent absorption of a hypothetical
2451 // future `Namespace` / `Deleted` arm before it lands on the enum
2452 // and its paired [`Semantic::as_str`] emitter arm) would
2453 // silently drift the parser's accept-set from the emitter's — a
2454 // downstream style-report re-loader that bound a prior report's
2455 // [`Self::as_str`] output back to the typed enum through this
2456 // parser would then bind a malformed byte-string to a plausibly-
2457 // wrong typed arm the caller does not route through any
2458 // fallback, silently misclassifying the reloaded row.
2459 //
2460 // Peer of the sibling
2461 // `caixa_lint::diagnostic::tests::severity_from_wire_rejects_unknown_byte_strings`
2462 // (5afff0e) /
2463 // `caixa_lint::diagnostic::tests::fix_safety_from_wire_rejects_unknown_byte_strings`
2464 // (bd505a1) /
2465 // `caixa_arch::report::tests::arch_verdict_from_wire_rejects_unknown_byte_strings`
2466 // (6afe564) /
2467 // `caixa_arch::invariants::tests::invariant_kind_from_wire_rejects_unknown_byte_strings`
2468 // (b9e4e61) rejection pins on the peer caixa-lint / caixa-arch
2469 // axes, and of the sibling
2470 // `caixa_kind_from_wire_rejects_unknown_byte_strings` (2aa6d23),
2471 // `caixa_dialeto_from_wire_rejects_unknown_byte_strings`
2472 // (d0e65ea),
2473 // `placement_strategy_from_wire_rejects_unknown_byte_strings`
2474 // (18c7342),
2475 // `dep_list_from_wire_returns_none_on_unknown_wire_scalar`
2476 // (45ee563), and
2477 // `path_shape_violation_from_wire_rejects_unknown_byte_strings`
2478 // (aebd9c6) rejection pins on the sibling caixa-core axes.
2479 //
2480 // The rejection set also covers overlapping-byte-string tags
2481 // from peer axes: caixa-lint `Severity::as_str` outputs
2482 // `"error"`/`"warning"`/`"info"`/`"hint"` and caixa-arch
2483 // `InvariantKind::as_str` outputs `"safety"`/`"compliance"`
2484 // share zero canonical byte-strings with the widened 16-arm
2485 // Semantic set here — a widened parser that admitted the peer's
2486 // arm on the sibling axis would still not admit an arm foreign
2487 // to the caixa-theme semantic-style discriminator's own accept-
2488 // set. Yet four peer-axis strings DO overlap with the
2489 // caixa-theme set here (`Severity`'s
2490 // `"error"`/`"warning"`/`"info"`/`"hint"` map identically onto
2491 // the caixa-theme diagnostic-severity sub-region
2492 // `Semantic::Error`/`Warning`/`Info`/`Hint`) — a widened parser
2493 // that admitted them under a different arm would collapse the
2494 // two axes and silently mislabel; the pin excludes those four
2495 // from the rejection set precisely because they must accept.
2496 for bad in [
2497 "",
2498 " ",
2499 "Keyword",
2500 "KEYWORD",
2501 "Symbol",
2502 "SYMBOL",
2503 "KeywordArg",
2504 "keyword_arg",
2505 "keywordarg",
2506 "String",
2507 "STRING",
2508 "Number",
2509 "Literal",
2510 "Comment",
2511 "Accent",
2512 "Muted",
2513 "Error",
2514 "ERROR",
2515 "Warning",
2516 "WARNING",
2517 "Info",
2518 "INFO",
2519 "Hint",
2520 "HINT",
2521 "Added",
2522 "ADDED",
2523 "Removed",
2524 "REMOVED",
2525 "Unchanged",
2526 "UNCHANGED",
2527 "kewyord",
2528 "sym",
2529 "kw",
2530 "str",
2531 "num",
2532 "lit",
2533 "cmt",
2534 "safe",
2535 "unsafe",
2536 "safety",
2537 "compliance",
2538 "proven",
2539 "rejected",
2540 "namespace",
2541 "deleted",
2542 "highlight",
2543 "identifier",
2544 "keyword ",
2545 " keyword",
2546 "keyword\n",
2547 "keyword\t",
2548 "keyword-arg ",
2549 " keyword-arg",
2550 "added ",
2551 " added",
2552 "unchanged ",
2553 " unchanged",
2554 ] {
2555 assert!(
2556 Semantic::from_wire(bad).is_none(),
2557 "Semantic::from_wire({bad:?}) must return None — the \
2558 parser's accept-set is exactly the 16 Semantic::as_str \
2559 outputs; a widening would silently split the parser's \
2560 accept-set from the emitter's arm-set",
2561 );
2562 }
2563 }
2564
2565 #[test]
2566 fn semantic_is_variant_predicates_are_const_fn() {
2567 // The [`gen_platform::IsVariant`] derive emits `const fn`
2568 // predicates on the peer [`caixa_core::CaixaKind`] /
2569 // [`caixa_core::upgrade::UpgradeInstruction`] /
2570 // [`caixa_core::supervisor::RestartStrategy`] /
2571 // [`caixa_core::supervisor::RestartPolicy`] closed-set typed
2572 // enums — pin the same posture on [`Semantic`] so a future
2573 // accidental downgrade to non-`const` (an added runtime helper
2574 // reachable only from a non-`const` context, a manual hand-
2575 // rolled `impl` that shadows the derive-generated method)
2576 // trips at caixa-theme build time rather than surfacing as a
2577 // downstream `const`-context regression far from the derive
2578 // declaration.
2579 const { assert!(Semantic::Keyword.is_keyword()) };
2580 const { assert!(Semantic::Error.is_error()) };
2581 const { assert!(Semantic::Added.is_added()) };
2582 const { assert!(Semantic::Unchanged.is_unchanged()) };
2583 }
2584
2585 #[test]
2586 fn semantic_try_from_str_routes_through_from_wire_accessor() {
2587 // Fail-before-pass-after byte-parity pin on the newly lifted
2588 // `impl TryFrom<&str> for Semantic` — asserts the standard-
2589 // library trait impl and the substrate-primitive
2590 // [`super::Semantic::from_wire`] `Option<Self>` accessor
2591 // resolve to the same 16-arm accept-set across every arm the
2592 // exhaustive [`super::Semantic::ALL`] slice enumerates. Any
2593 // future silent detour that routes the trait impl through a
2594 // divergent projection (a per-arm inline `match s { "keyword"
2595 // => Ok(Self::Keyword), … }` re-inlining that opens a
2596 // compile-time link to the un-lifted arm-literal, a silent
2597 // case-fold that admits `"Keyword"` / `"KEYWORD"` and would
2598 // collide the canonical-lowercase accept-set the emitter
2599 // dispatches on) trips at caixa-theme test time under
2600 // `assert_eq!` rather than at a downstream
2601 // `impl TryFrom<&str>`-bound consumer's silent split. Sweeps
2602 // every one of the 16 arms [`super::Semantic::ALL`] carries so
2603 // no arm's projection is covered only by the sibling method-
2604 // named `from_wire` path.
2605 //
2606 // Peer of the sibling
2607 // [`caixa_core::kind::tests::caixa_kind_try_from_str_routes_through_from_wire_accessor`]
2608 // (3c83606),
2609 // [`caixa_core::dialeto::tests::caixa_dialeto_try_from_str_routes_through_from_wire_accessor`]
2610 // (bf33136),
2611 // `placement_strategy_try_from_str_routes_through_from_wire_accessor`
2612 // (6fd00cd),
2613 // `rate_limit_unit_try_from_str_routes_through_from_suffix_accessor`
2614 // (bf78400),
2615 // `path_shape_violation_try_from_str_routes_through_from_wire_accessor`
2616 // (e67e48a),
2617 // `caixa_arch::invariants::tests::invariant_kind_try_from_str_routes_through_from_wire_accessor`
2618 // (e21a857),
2619 // `caixa_arch::report::tests::arch_verdict_try_from_str_routes_through_from_wire_accessor`
2620 // (0a4cc45),
2621 // `caixa_lint::diagnostic::tests::severity_try_from_str_routes_through_from_wire_accessor`
2622 // (a7bf74c), and
2623 // `caixa_lint::diagnostic::tests::fix_safety_try_from_str_routes_through_from_wire_accessor`
2624 // (df86c94) — extends the trait-idiomatic reverse-projection
2625 // axis onto the first closed-set fieldless typed enum on the
2626 // caixa-theme surface (the semantic-style axis).
2627 for &variant in Semantic::ALL {
2628 let wire = variant.as_str();
2629 assert_eq!(
2630 <Semantic as TryFrom<&str>>::try_from(wire),
2631 Ok(variant),
2632 "TryFrom<&str> impl on Semantic must round-trip \
2633 Semantic::{variant:?}.as_str() = {wire:?} back to \
2634 Ok(Semantic::{variant:?}) — divergence from \
2635 Semantic::from_wire signals a silent detour off the \
2636 substrate-primitive accessor",
2637 );
2638 assert_eq!(
2639 <Semantic as TryFrom<&str>>::try_from(wire).ok(),
2640 Semantic::from_wire(wire),
2641 "TryFrom<&str> ok()-projection on {wire:?} must \
2642 byte-equal Semantic::from_wire on the same input",
2643 );
2644 }
2645 }
2646
2647 #[test]
2648 fn semantic_try_from_str_rejects_unknown_byte_strings() {
2649 // Rejection witness on the `impl TryFrom<&str> for Semantic` —
2650 // sweeps a candidate set of byte-strings outside the 16-arm
2651 // canonical-lowercase kebab wire accept-set the sibling
2652 // [`super::Semantic::as_str`] emits and asserts every one
2653 // lands on `Err(())`, so a future accidental widening of the
2654 // trait impl's accept-set (a stray additional
2655 // `_ if s.eq_ignore_ascii_case("keyword") => Ok(…)` case-fold
2656 // path, a silent acceptance of the pre-lift PascalCase Debug-
2657 // derived shapes `"Keyword"` / `"Symbol"` / `"KeywordArg"` on
2658 // the wire axis, a Levenshtein-forgiving arm-lookup that
2659 // admits `"kwd"` / `"sym"` / `"kw"` typos — the exact form a
2660 // `format!("{:?}", …).to_lowercase()` round-trip on the paired
2661 // [`std::fmt::Debug`] derive would otherwise land on) trips at
2662 // caixa-theme test time. The candidate set includes the empty
2663 // string, whitespace-only padding, uppercase / PascalCase
2664 // rebrand candidates, Levenshtein-neighbor typos, sibling
2665 // closed-set-enum canonical tags not shared with this axis
2666 // (peer `caixa_lint::diagnostic::FixSafety::as_str` two-arm
2667 // `"safe"` / `"unsafe"`, peer `caixa_arch::InvariantKind::as_str`
2668 // three-arm `"safety"` / `"compliance"`, peer
2669 // `caixa_arch::ArchVerdict::as_str` two-arm `"proven"` /
2670 // `"rejected"`), the trajectory-item candidates
2671 // (`"namespace"`, `"deleted"`) the sibling [`Semantic::ALL`]
2672 // doc block already names, whitespace-padded canonical tags,
2673 // and CamelCase spellings of the multi-word `KeywordArg`
2674 // variant (`"KeywordArg"`, `"keywordarg"`, `"keyword_arg"`,
2675 // `"keyword.arg"`) that would silently admit
2676 // if the accept-set widened to a case-fold or separator-
2677 // normalization rule.
2678 //
2679 // Peer of the sibling
2680 // `caixa_kind_try_from_str_rejects_unknown_byte_strings`
2681 // (3c83606),
2682 // `caixa_dialeto_try_from_str_rejects_unknown_byte_strings`
2683 // (bf33136),
2684 // `rate_limit_unit_try_from_str_rejects_unknown_byte_strings`
2685 // (bf78400),
2686 // `path_shape_violation_try_from_str_rejects_unknown_byte_strings`
2687 // (e67e48a),
2688 // `invariant_kind_try_from_str_rejects_unknown_byte_strings`
2689 // (e21a857),
2690 // `arch_verdict_try_from_str_rejects_unknown_byte_strings`
2691 // (0a4cc45),
2692 // `severity_try_from_str_rejects_unknown_byte_strings`
2693 // (a7bf74c), and
2694 // `fix_safety_try_from_str_rejects_unknown_byte_strings`
2695 // (df86c94) rejection pins on the sibling closed-set typed-
2696 // enum trait-idiomatic reverse-projection axes.
2697 for bad in [
2698 "",
2699 " ",
2700 "Keyword",
2701 "KEYWORD",
2702 "Symbol",
2703 "KeywordArg",
2704 "keywordarg",
2705 "keyword_arg",
2706 "keyword.arg",
2707 "String",
2708 "Number",
2709 "Literal",
2710 "Comment",
2711 "Accent",
2712 "Muted",
2713 "Error",
2714 "ERROR",
2715 "Warning",
2716 "Info",
2717 "Hint",
2718 "Added",
2719 "Removed",
2720 "Unchanged",
2721 "kwd",
2722 "sym",
2723 "kw",
2724 "str",
2725 "num",
2726 "lit",
2727 "cmt",
2728 "safe",
2729 "unsafe",
2730 "safety",
2731 "compliance",
2732 "proven",
2733 "rejected",
2734 "namespace",
2735 "deleted",
2736 "highlight",
2737 "identifier",
2738 "keyword ",
2739 " keyword",
2740 "keyword\n",
2741 "keyword\t",
2742 "keyword-arg ",
2743 " keyword-arg",
2744 "added ",
2745 " added",
2746 "unchanged ",
2747 " unchanged",
2748 ] {
2749 assert_eq!(
2750 <Semantic as TryFrom<&str>>::try_from(bad),
2751 Err(()),
2752 "TryFrom<&str> for Semantic({bad:?}) must return \
2753 Err(()) — the trait impl's accept-set is exactly the \
2754 16 Semantic::as_str outputs; a widening would \
2755 silently split the trait impl's accept-set from the \
2756 emitter's arm-set",
2757 );
2758 }
2759 }
2760
2761 #[test]
2762 fn semantic_try_from_str_and_from_wire_partition_the_accept_set() {
2763 // Cross-axis partition pin: the trait-idiomatic
2764 // [`TryFrom<&str>`] and the method-named
2765 // [`super::Semantic::from_wire`] projections must return
2766 // equivalent decisions on every input — the trait impl's
2767 // `.ok()` project-out from `Result<Self, ()>` and the method's
2768 // `Option<Self>` return must byte-equal each other on both
2769 // accepts and rejects. A future silent bifurcation (the trait
2770 // impl gaining a case-fold path the method does not carry, the
2771 // method gaining a synonym alias the trait impl does not
2772 // honor) trips at caixa-theme test time under a single pin
2773 // rather than at a downstream generic-bound consumer that
2774 // dispatches through one axis while a peer dispatches through
2775 // the other. Sweeps both the 16-arm accept-set (via
2776 // [`super::Semantic::ALL`] threaded through
2777 // [`super::Semantic::as_str`]) and a canonical rejection
2778 // sample so both halves of the partition are covered. Peer of
2779 // the sibling
2780 // `severity_try_from_str_and_from_wire_partition_the_accept_set`
2781 // (a7bf74c) and
2782 // `fix_safety_try_from_str_and_from_wire_partition_the_accept_set`
2783 // (df86c94) partition pins.
2784 for &variant in Semantic::ALL {
2785 let wire = variant.as_str();
2786 assert_eq!(
2787 <Semantic as TryFrom<&str>>::try_from(wire).ok(),
2788 Semantic::from_wire(wire),
2789 "TryFrom<&str>::ok() and from_wire must agree on \
2790 Semantic::{variant:?}.as_str() = {wire:?}",
2791 );
2792 }
2793 for bad in [
2794 "",
2795 "Keyword",
2796 "unknown",
2797 "safety",
2798 "safe",
2799 "proven",
2800 "namespace",
2801 "keywordarg",
2802 ] {
2803 assert_eq!(
2804 <Semantic as TryFrom<&str>>::try_from(bad).ok(),
2805 Semantic::from_wire(bad),
2806 "TryFrom<&str>::ok() and from_wire must agree on the \
2807 rejection outcome for {bad:?}",
2808 );
2809 }
2810 }
2811
2812 #[test]
2813 fn semantic_from_str_routes_through_try_from_str_impl() {
2814 // Fail-before-pass-after byte-parity pin on the newly lifted
2815 // `impl std::str::FromStr for Semantic` — asserts the standard-
2816 // library `.parse()` parse-axis entry point and the paired
2817 // [`super::Semantic::try_from`] `TryFrom<&str>` impl (which in
2818 // turn routes through the substrate-primitive
2819 // [`super::Semantic::from_wire`] `Option<Self>` accessor)
2820 // resolve to the same 16-arm canonical-lowercase-kebab accept-
2821 // set across every arm the exhaustive [`super::Semantic::ALL`]
2822 // slice enumerates. Extends the substrate-wide `FromStr`
2823 // parse-axis campaign — opened on
2824 // [`caixa_core::dep::DepList`] via 6167092, then
2825 // [`caixa_core::CaixaKind`] (9867432),
2826 // [`caixa_core::aplicacao::PlacementStrategy`] (62ef49a),
2827 // [`caixa_core::CaixaDialeto`] (ff01b2f),
2828 // [`caixa_arch::invariants::InvariantKind`] (fb16072),
2829 // [`caixa_arch::report::ArchVerdict`] (40e9dfd),
2830 // `caixa_lint::diagnostic::Severity` (6b0a08c),
2831 // `caixa_lint::diagnostic::FixSafety` (eb6942b), and
2832 // [`caixa_core::render::PathShapeViolation`] (b0b578c) — onto
2833 // the *first* closed-set fieldless typed enum on the caixa-
2834 // theme surface: the 16-arm semantic-style accept-set every
2835 // per-`Semantic` paint dispatch, every future `caixa-lsp`-side
2836 // per-`SemanticTokenType` wire-up, every future `caixa.nvim`
2837 // per-highlight-group re-loader, and every future `blackmatter-
2838 // shell` per-arm `data-semantic="<kebab>"` DOM-attribute
2839 // emission dispatches through. The peer method-named
2840 // `from_wire` accessor and the paired `TryFrom<&str>` trait
2841 // impl fix the 16-arm canonical-lowercase-kebab accept-set;
2842 // this pin locks the `FromStr::from_str` trait entry point
2843 // onto the same set so any future divergence (a stray per-arm
2844 // `match s` re-inlining that opens a compile-time link to an
2845 // un-lifted arm-literal outside the paired
2846 // [`super::CAIXA_THEME_SEMANTIC_WIRE_*`] consts, a swap onto a
2847 // hand-rolled parser that widens the accept-set past those 16
2848 // wire constants) trips at caixa-theme test time. Also covers
2849 // the stdlib `.parse()` short-form witness:
2850 // `.parse::<Semantic>()` is the `T: FromStr`-bounded generic
2851 // every clap-style arg-parser, `serde` string-tagged
2852 // deserializer, and generic `<T: FromStr>`-bound loader reaches
2853 // for — the pin asserts both `<T as FromStr>::from_str` and
2854 // `.parse::<T>()` resolve to the same 16-arm accept-set.
2855 use std::str::FromStr;
2856 for &variant in Semantic::ALL {
2857 let wire = variant.as_str();
2858 assert_eq!(
2859 <Semantic as FromStr>::from_str(wire),
2860 Ok(variant),
2861 "FromStr impl on Semantic must round-trip \
2862 Semantic::{variant:?}.as_str() = {wire:?} back to \
2863 Ok(Semantic::{variant:?}) — divergence from the paired \
2864 TryFrom<&str> impl / Semantic::from_wire signals a \
2865 silent detour off the substrate-primitive accessor",
2866 );
2867 assert_eq!(
2868 wire.parse::<Semantic>(),
2869 Ok(variant),
2870 "stdlib .parse::<Semantic>() short-form on \
2871 Semantic::{variant:?}.as_str() = {wire:?} must route \
2872 through the lifted FromStr impl and reach \
2873 Ok(Semantic::{variant:?})",
2874 );
2875 assert_eq!(
2876 <Semantic as FromStr>::from_str(wire).ok(),
2877 Semantic::from_wire(wire),
2878 "FromStr::from_str ok()-projection on {wire:?} must \
2879 byte-equal Semantic::from_wire on the same input — \
2880 the two reverse-projection axes must resolve to the \
2881 same 16-arm canonical-lowercase-kebab accept-set",
2882 );
2883 assert_eq!(
2884 <Semantic as FromStr>::from_str(wire),
2885 <Semantic as TryFrom<&str>>::try_from(wire),
2886 "FromStr::from_str and TryFrom<&str>::try_from must \
2887 byte-equal on every arm — FromStr delegates to \
2888 TryFrom<&str> by construction; divergence signals a \
2889 stray reroute onto a hand-rolled parser",
2890 );
2891 }
2892 }
2893
2894 #[test]
2895 fn semantic_from_str_rejects_unknown_byte_strings() {
2896 // Rejection witness on the `impl std::str::FromStr for
2897 // Semantic` — sweeps a candidate set of byte-strings outside
2898 // the 16-arm canonical-lowercase-kebab wire accept-set the
2899 // sibling [`super::Semantic::as_str`] emits and asserts every
2900 // one lands on `Err(())`, so a future accidental widening of
2901 // the trait impl's accept-set (a stray case-fold that admits
2902 // the pre-lift PascalCase Debug-derived shapes `"Keyword"` /
2903 // `"KeywordArg"` / … on the wire axis, an underscore-tolerant
2904 // arm-lookup that admits `"keyword_arg"` — the exact drift
2905 // form a `format!("{:?}", …).to_lowercase()` round-trip on the
2906 // paired [`std::fmt::Debug`] derive or a
2907 // `#[serde(rename_all = "snake_case")]` drift would land on,
2908 // the drift footgun the emitter's documentation explicitly
2909 // names as the reason the substrate-canonical
2910 // lowercase-kebab tag set exists) trips at caixa-theme test
2911 // time. The candidate set spans the empty string, whitespace-
2912 // only padding, uppercase / PascalCase rebrand candidates,
2913 // Levenshtein-neighbor typos, snake_case rebrand candidates,
2914 // sibling closed-set-enum canonical tags that do *not* overlap
2915 // the Semantic accept-set (the `"error"` / `"warning"` /
2916 // `"info"` / `"hint"` peer
2917 // `caixa_lint::diagnostic::Severity::as_str` four-arm set is
2918 // deliberately excluded from the rejection sweep because those
2919 // four tags coincide byte-for-byte with the Semantic axis'
2920 // diagnostic-severity paint arms and therefore *must* be
2921 // accepted by construction — the accepted-set witness above
2922 // covers them), the peer
2923 // `caixa_lint::diagnostic::FixSafety::as_str` two-arm set
2924 // (`"safe"` / `"unsafe"`), the peer
2925 // `caixa_arch::invariants::InvariantKind::as_str` three-arm
2926 // set (`"safety"` / `"compliance"` / `"performance"`), the
2927 // peer arch-verdict two-arm accept-set (`"proven"` /
2928 // `"rejected"`), cross-crate kind / strategy tags, and
2929 // trailing/leading-whitespace-padded canonical tags. Pairs the
2930 // `<T as FromStr>::from_str` and stdlib `.parse()` short-form
2931 // witnesses so a future divergence between the two parse-axis
2932 // entry points (a hand-rolled `.parse` override that bypasses
2933 // the delegated `FromStr` impl) trips here.
2934 use std::str::FromStr;
2935 for bad in [
2936 "",
2937 " ",
2938 "\t",
2939 "\n",
2940 "Keyword",
2941 "KEYWORD",
2942 "KeywordArg",
2943 "keyword_arg",
2944 "keyword arg",
2945 "keywordarg",
2946 "keywor",
2947 "Symbol",
2948 "SYMBOL",
2949 "Comment",
2950 "unknown",
2951 "biblioteca",
2952 "servico",
2953 "safety",
2954 "compliance",
2955 "performance",
2956 "proven",
2957 "rejected",
2958 "safe",
2959 "unsafe",
2960 "one-for-one",
2961 "empty",
2962 "absolute",
2963 "parent-escape",
2964 "keyword ",
2965 " keyword",
2966 "keyword\n",
2967 "keyword\t",
2968 "\"keyword\"",
2969 ] {
2970 assert_eq!(
2971 <Semantic as FromStr>::from_str(bad),
2972 Err(()),
2973 "FromStr for Semantic({bad:?}) must return Err(()) — \
2974 the trait impl's accept-set is exactly the 16 \
2975 Semantic::as_str outputs; a widening would silently \
2976 split the FromStr impl's accept-set from the \
2977 emitter's arm-set",
2978 );
2979 assert_eq!(
2980 bad.parse::<Semantic>(),
2981 Err(()),
2982 "stdlib .parse::<Semantic>() short-form on {bad:?} \
2983 must route through the lifted FromStr impl and \
2984 reject with Err(())",
2985 );
2986 }
2987 }
2988
2989 #[test]
2990 fn semantic_from_into_static_str_routes_through_as_str_accessor() {
2991 // Fail-before-pass-after byte-parity pin on the newly lifted
2992 // `impl From<Semantic> for &'static str` — asserts the standard-
2993 // library trait impl and the substrate-primitive
2994 // [`super::Semantic::as_str`] `pub const fn` accessor resolve to
2995 // the same 16-arm canonical-lowercase kebab emit-set across every
2996 // arm the exhaustive [`super::Semantic::ALL`] slice enumerates.
2997 // Any future silent detour that routes the trait impl through a
2998 // divergent projection (a per-arm inline `match sem { Keyword =>
2999 // "keyword", … }` re-inlining that opens a compile-time link to
3000 // the un-lifted arm-literal outside the paired
3001 // [`super::Semantic::as_str`] dispatch, a swap onto a
3002 // `format!("{:?}", …).to_lowercase()` round-trip through the
3003 // `#[derive(Debug)]` output whose stability is *not* guaranteed
3004 // and would silently reroute the semantic-style tag through a
3005 // stale byte-string with no downstream signal until an operator
3006 // scrolled the theme-paint terminal, a `#[serde(rename_all = "…")]`
3007 // attribute drift that quietly forks one axis) trips at
3008 // caixa-theme test time under `assert_eq!` rather than at a
3009 // downstream `impl Into<&'static str>`-bound consumer's silent
3010 // split. Sweeps every one of the 16 arms
3011 // [`super::Semantic::ALL`] carries so no arm's projection is
3012 // covered only by the sibling method-named `as_str` /
3013 // [`std::fmt::Display`] / [`AsRef<str>`] paths. Materializes
3014 // three `<&'static str as From<Semantic>>::from` outputs in
3015 // `const`-shape bindings against the paired
3016 // [`super::Semantic::as_str`] `pub const fn` accessor to make
3017 // the `'static` lifetime promise a build-time invariant — a
3018 // future accidental downgrade of any arm's inline canonical-
3019 // lowercase kebab byte-string to a non-`&'static str` (a
3020 // `String::leak()`-produced return, a `Box::leak`-cast, an
3021 // intermediate lifetime-erasing helper) trips at caixa-theme
3022 // build time rather than at a downstream `'static`-bound
3023 // consumer.
3024 //
3025 // Peer of the sibling
3026 // [`caixa_core::supervisor::tests::restart_strategy_from_into_static_str_routes_through_as_str_accessor`]
3027 // (523157d),
3028 // [`caixa_core::supervisor::tests::restart_policy_from_into_static_str_routes_through_as_str_accessor`]
3029 // (9fb37d0),
3030 // [`caixa_core::kind::tests::caixa_kind_from_into_static_str_routes_through_as_str_accessor`]
3031 // (edb827b),
3032 // [`caixa_core::dialeto::tests::caixa_dialeto_from_into_static_str_routes_through_as_str_accessor`]
3033 // (c189a6f),
3034 // [`caixa_core::aplicacao::tests::placement_strategy_from_into_static_str_routes_through_as_str_accessor`]
3035 // (afa3562),
3036 // [`caixa_core::aplicacao::tests::wit_shape_from_into_static_str_routes_through_as_str_accessor`]
3037 // (56998ec),
3038 // [`caixa_core::aplicacao::tests::rate_limit_unit_from_into_static_str_routes_through_as_suffix_accessor`]
3039 // (7fdfbf4),
3040 // [`caixa_core::render::tests::path_shape_violation_from_into_static_str_routes_through_as_str_accessor`]
3041 // (070a6de),
3042 // `caixa_arch::invariants::tests::invariant_kind_from_into_static_str_routes_through_as_str_accessor`
3043 // (f2ca7bc),
3044 // `caixa_arch::report::tests::arch_verdict_from_into_static_str_routes_through_as_str_accessor`
3045 // (d4559cb),
3046 // `caixa_lint::diagnostic::tests::severity_from_into_static_str_routes_through_as_str_accessor`
3047 // (5cc3b8b), and
3048 // `caixa_lint::diagnostic::tests::fix_safety_from_into_static_str_routes_through_as_str_accessor`
3049 // (2a56127) pins on the sibling closed-set typed-enum forward-
3050 // projection axes — extends the trait-idiomatic forward-
3051 // projection axis onto the first closed-set fieldless typed
3052 // enum on the caixa-theme surface (the semantic-style axis),
3053 // leaving `caixa_provedor::FerriteRuntime` as the last outside-
3054 // caixa-core closed-set fieldless typed enum whose trait-
3055 // idiomatic forward axis is still open.
3056 const KEYWORD: &str = Semantic::Keyword.as_str();
3057 const KEYWORD_ARG: &str = Semantic::KeywordArg.as_str();
3058 const UNCHANGED: &str = Semantic::Unchanged.as_str();
3059 for &variant in Semantic::ALL {
3060 let via_trait: &'static str = <&'static str as From<Semantic>>::from(variant);
3061 let via_method: &'static str = variant.as_str();
3062 assert_eq!(
3063 via_trait, via_method,
3064 "From<Semantic> for &'static str impl must round-trip \
3065 Semantic::{variant:?} to the same canonical-lowercase \
3066 kebab byte-string Semantic::as_str returns — divergence \
3067 signals a silent detour off the substrate-primitive \
3068 accessor"
3069 );
3070 let via_into: &'static str = variant.into();
3071 assert_eq!(
3072 via_into, via_method,
3073 "Into<&'static str>::into on Semantic::{variant:?} must \
3074 byte-equal Semantic::as_str on the same input — the \
3075 blanket-derived Into shape must resolve to the same \
3076 as_str dispatch as the explicit From impl"
3077 );
3078 }
3079 assert_eq!(
3080 [KEYWORD, KEYWORD_ARG, UNCHANGED],
3081 ["keyword", "keyword-arg", "unchanged"],
3082 "const-context Semantic::as_str must resolve to the \
3083 canonical-lowercase kebab byte-strings — a future \
3084 accidental downgrade of any arm to a non-const or non-\
3085 static byte-string breaks the `&'static str`-lifetime \
3086 promise the paired From<Semantic> for &'static str impl \
3087 carries by construction"
3088 );
3089 }
3090
3091 #[test]
3092 fn semantic_from_into_static_str_and_as_str_partition_the_emit_set() {
3093 // Cross-axis partition pin: the paired trait-idiomatic
3094 // `From<Semantic> for &'static str` forward projection and the
3095 // method-named [`super::Semantic::as_str`] forward projection
3096 // must resolve identically on *every* arm, not just the ones
3097 // named in the primary byte-parity pin above. Sweeps every
3098 // [`super::Semantic::ALL`] arm and asserts the trait's
3099 // `From::from` output byte-equals the method-named accessor's
3100 // return-value on each, locking the two forward-projection paths
3101 // together by construction so any future detour (a stray `From`
3102 // special-case that lands on a divergent per-arm literal outside
3103 // the paired `as_str` dispatch, a hypothetical rebrand touching
3104 // one axis without the other) trips at caixa-theme test time.
3105 //
3106 // Peer of the sibling forward-projection partition pins
3107 // [`caixa_core::supervisor::tests::restart_strategy_from_into_static_str_and_as_str_partition_the_emit_set`]
3108 // (523157d),
3109 // [`caixa_core::supervisor::tests::restart_policy_from_into_static_str_and_as_str_partition_the_emit_set`]
3110 // (9fb37d0),
3111 // [`caixa_core::kind::tests::caixa_kind_from_into_static_str_and_as_str_partition_the_emit_set`]
3112 // (edb827b),
3113 // [`caixa_core::dialeto::tests::caixa_dialeto_from_into_static_str_and_as_str_partition_the_emit_set`]
3114 // (c189a6f),
3115 // [`caixa_core::aplicacao::tests::placement_strategy_from_into_static_str_and_as_str_partition_the_emit_set`]
3116 // (afa3562),
3117 // [`caixa_core::aplicacao::tests::wit_shape_from_into_static_str_and_as_str_partition_the_emit_set`]
3118 // (56998ec),
3119 // [`caixa_core::aplicacao::tests::rate_limit_unit_from_into_static_str_and_as_suffix_partition_the_emit_set`]
3120 // (7fdfbf4),
3121 // [`caixa_core::render::tests::path_shape_violation_from_into_static_str_and_as_str_partition_the_emit_set`]
3122 // (070a6de),
3123 // `caixa_arch::invariants::tests::invariant_kind_from_into_static_str_and_as_str_partition_the_emit_set`
3124 // (f2ca7bc),
3125 // `caixa_arch::report::tests::arch_verdict_from_into_static_str_and_as_str_partition_the_emit_set`
3126 // (d4559cb),
3127 // `caixa_lint::diagnostic::tests::severity_from_into_static_str_and_as_str_partition_the_emit_set`
3128 // (5cc3b8b), and
3129 // `caixa_lint::diagnostic::tests::fix_safety_from_into_static_str_and_as_str_partition_the_emit_set`
3130 // (2a56127) — extends the round-trip discipline onto the first
3131 // closed-set fieldless typed enum on the caixa-theme surface,
3132 // closing the two-way `Self ↔ &'static str` round-trip on the
3133 // trait-idiomatic pair (`From<Self> for &'static str` +
3134 // `TryFrom<&str> for Self`) as well as the pre-existing method-
3135 // named pair (`as_str` + `from_wire`).
3136 for &variant in Semantic::ALL {
3137 let via_trait: &'static str = <&'static str as From<Semantic>>::from(variant);
3138 let via_method: &'static str = variant.as_str();
3139 assert_eq!(
3140 via_trait, via_method,
3141 "From<Semantic> for &'static str and Semantic::as_str \
3142 must resolve identically on Semantic::{variant:?} — \
3143 divergence signals the two forward-projection paths \
3144 have drifted onto different emit-sets"
3145 );
3146 }
3147 // Round-trip witness: every arm's forward `From` output re-parses
3148 // through the paired trait-idiomatic `TryFrom<&str>` back to the
3149 // original variant. Closes the two-way `Semantic ↔ &'static str`
3150 // round-trip on the trait-idiomatic axis pair directly (no wire-
3151 // vocab intermediate — the emit-side [`super::Semantic::as_str`]
3152 // and the parse-side [`super::Semantic::from_wire`] dispatch on
3153 // the same 16 inline canonical-lowercase kebab byte-strings by
3154 // construction, so round-tripping through the paired
3155 // `From<Self> for &'static str` + `TryFrom<&str> for Self` trait
3156 // impls composes to the identity on `Semantic::ALL`).
3157 for &variant in Semantic::ALL {
3158 let emitted: &'static str = <&'static str as From<Semantic>>::from(variant);
3159 let reparsed = <Semantic as TryFrom<&str>>::try_from(emitted).unwrap_or_else(|()| {
3160 panic!(
3161 "TryFrom<&str> for Semantic must accept every \
3162 From<Semantic> for &'static str output — got \
3163 Err(()) for Semantic::{variant:?}'s emit \
3164 byte-string {emitted:?}"
3165 )
3166 });
3167 assert_eq!(
3168 reparsed, variant,
3169 "trait-idiomatic Semantic ↔ &'static str round-trip \
3170 must be the identity on Semantic::{variant:?} — the \
3171 From<Self> for &'static str + TryFrom<&str> for Self \
3172 pair must compose to the identity on the closed 16-arm \
3173 accept-set"
3174 );
3175 }
3176 }
3177
3178 #[test]
3179 fn semantic_from_borrowed_into_static_str_routes_through_as_str_accessor() {
3180 // Fail-before-pass-after byte-parity pin on the newly lifted
3181 // `impl From<&Semantic> for &'static str` — asserts the
3182 // borrowed-input standard-library trait impl and the substrate-
3183 // primitive [`super::Semantic::as_str`] `pub const fn` accessor
3184 // resolve to the same 16-arm canonical-lowercase kebab emit-set
3185 // across every arm the exhaustive [`super::Semantic::ALL`]
3186 // slice enumerates. Rust's `From` trait does not auto-derive
3187 // the borrowed-input sibling from a paired owned-input impl
3188 // (no `impl<T, U> From<&T> for U where T: Copy, U: From<T>`
3189 // blanket in `core`), so the borrowed-input axis is a distinct
3190 // trait-idiomatic surface that a `.iter().map(Into::into)`
3191 // shape over [`super::Semantic::ALL`] (whose iterator yields
3192 // `&Semantic`, not `Semantic`) reaches through this impl and
3193 // no other — the paired owned-input [`From<Semantic>`] impl
3194 // requires an explicit `.copied()` / dereference before the
3195 // trait fires. Materializes three
3196 // `<&'static str as From<&Semantic>>::from` outputs in
3197 // `const`-shape bindings against the paired
3198 // [`super::Semantic::as_str`] `pub const fn` accessor to make
3199 // the `'static` lifetime promise a build-time invariant — a
3200 // future accidental downgrade of any arm's inline canonical-
3201 // lowercase kebab byte-string to a non-`&'static str` (a
3202 // `String::leak()`-produced return, a `Box::leak`-cast, an
3203 // intermediate lifetime-erasing helper) trips at caixa-theme
3204 // build time rather than at a downstream `'static`-bound
3205 // consumer.
3206 //
3207 // Peer of the sibling
3208 // `caixa_provedor::ferrite::tests::ferrite_runtime_from_borrowed_into_static_str_routes_through_variant_slug_accessor`
3209 // (676d693) pin on the outside-`caixa-core` closed-set-enum
3210 // borrowed-input axis — extends the trait-idiomatic borrowed-
3211 // input forward-projection axis onto the last remaining
3212 // closed-set fieldless typed enum on the substrate surface
3213 // (the caixa-theme semantic-style 16-arm axis), closing the
3214 // substrate-wide 2×2-completion campaign's borrowed-input
3215 // `&'static str`-returning corner.
3216 const KEYWORD: &str = Semantic::Keyword.as_str();
3217 const KEYWORD_ARG: &str = Semantic::KeywordArg.as_str();
3218 const UNCHANGED: &str = Semantic::Unchanged.as_str();
3219 for variant in Semantic::ALL {
3220 let via_trait: &'static str = <&'static str as From<&Semantic>>::from(variant);
3221 let via_method: &'static str = variant.as_str();
3222 assert_eq!(
3223 via_trait, via_method,
3224 "From<&Semantic> for &'static str impl must round-trip \
3225 &Semantic::{variant:?} to the same canonical-lowercase \
3226 kebab byte-string Semantic::as_str returns — divergence \
3227 signals a silent detour off the substrate-primitive \
3228 accessor"
3229 );
3230 let via_into: &'static str = variant.into();
3231 assert_eq!(
3232 via_into, via_method,
3233 "Into<&'static str>::into on &Semantic::{variant:?} must \
3234 byte-equal Semantic::as_str on the same input — the \
3235 blanket-derived Into shape on the borrowed-input axis \
3236 must resolve to the same as_str dispatch as the \
3237 explicit From impl"
3238 );
3239 }
3240 assert_eq!(
3241 [KEYWORD, KEYWORD_ARG, UNCHANGED],
3242 ["keyword", "keyword-arg", "unchanged"],
3243 "const-context Semantic::as_str must resolve to the \
3244 canonical-lowercase kebab byte-strings — a future \
3245 accidental downgrade of any arm to a non-const or non-\
3246 static byte-string breaks the `&'static str`-lifetime \
3247 promise the paired From<&Semantic> for &'static str impl \
3248 carries by construction"
3249 );
3250 }
3251
3252 #[test]
3253 fn semantic_from_owned_and_borrowed_into_static_str_agree_on_every_arm() {
3254 // Cross-axis partition pin: the paired trait-idiomatic
3255 // `From<Semantic> for &'static str` owned-input forward
3256 // projection and the newly lifted
3257 // `From<&Semantic> for &'static str` borrowed-input forward
3258 // projection must resolve identically on *every* arm the
3259 // exhaustive [`super::Semantic::ALL`] slice enumerates. Locks
3260 // the two trait-idiomatic forward-projection paths together by
3261 // construction so any future detour (a stray borrowed-input
3262 // `From` special-case that lands on a divergent per-arm literal
3263 // outside the paired `as_str` dispatch, a hypothetical rebrand
3264 // touching one axis without the other) trips at caixa-theme
3265 // test time under `assert_eq!` rather than at a downstream
3266 // consumer split. Witnesses the borrowed-input axis with a
3267 // `.iter().map(Into::into)` pipe over `Semantic::ALL` (whose
3268 // iterator yields `&Semantic`, not `Semantic`, so the pipe
3269 // fires through the borrowed-input axis alone).
3270 //
3271 // Peer of the sibling
3272 // `caixa_provedor::ferrite::tests::ferrite_runtime_from_owned_and_borrowed_into_static_str_agree_on_every_arm`
3273 // (676d693) — extends the owned/borrowed-cross-axis partition
3274 // discipline onto the last remaining substrate-wide closed-set
3275 // fieldless typed enum whose borrowed-input axis was still
3276 // open.
3277 for &variant in Semantic::ALL {
3278 let via_owned: &'static str = <&'static str as From<Semantic>>::from(variant);
3279 let via_borrowed: &'static str = <&'static str as From<&Semantic>>::from(&variant);
3280 assert_eq!(
3281 via_owned, via_borrowed,
3282 "From<Semantic> for &'static str and From<&Semantic> \
3283 for &'static str must agree on Semantic::{variant:?} \
3284 — divergence signals the owned-input and borrowed-\
3285 input forward-projection paths have drifted onto \
3286 different emit-sets"
3287 );
3288 }
3289 let via_pipe: Vec<&'static str> = Semantic::ALL.iter().map(Into::into).collect();
3290 let via_method: Vec<&'static str> = Semantic::ALL.iter().map(|s| s.as_str()).collect();
3291 assert_eq!(
3292 via_pipe, via_method,
3293 "Semantic::ALL.iter().map(Into::into) must resolve to the \
3294 same per-arm canonical-lowercase kebab byte-string \
3295 sequence Semantic::as_str returns across every arm — the \
3296 iterator yields &Semantic, so this pipe fires through the \
3297 borrowed-input From<&Semantic> for &'static str axis and \
3298 witnesses the newly lifted impl's arm-set matches the \
3299 substrate-primitive accessor without a spurious Copy deref"
3300 );
3301 }
3302
3303 #[test]
3304 fn semantic_from_into_owned_string_routes_through_as_str_accessor() {
3305 // Fail-before-pass-after byte-parity pin on the newly lifted
3306 // `impl From<Semantic> for String` — asserts the owned-
3307 // `String`-returning standard-library trait impl and the
3308 // substrate-primitive [`super::Semantic::as_str`] `pub const
3309 // fn` accessor resolve to the same 16-arm canonical-lowercase
3310 // kebab emit-set across every arm the exhaustive
3311 // [`super::Semantic::ALL`] slice enumerates. Rust's standard
3312 // library does not carry a blanket
3313 // `impl<T: AsRef<str>> From<T> for String`, so the owned-
3314 // `String` axis is a distinct trait-idiomatic surface that a
3315 // `let key: String = sem.into();`-shaped downstream call site
3316 // reaches through this impl and no other — the sibling
3317 // `&'static str`-returning axes force an explicit
3318 // `.to_owned()` / [`String::from`] restatement whose type
3319 // bounds have no compile-time link to the substrate primitive.
3320 // Sweeps every one of the 16 arms
3321 // [`super::Semantic::ALL`] carries so no arm's projection is
3322 // covered only by the sibling method-named `as_str` /
3323 // [`std::fmt::Display`] / [`AsRef<str>`] / owned-input
3324 // `&'static str`-returning paths.
3325 //
3326 // Peer of the sibling
3327 // `caixa_provedor::ferrite::tests::ferrite_runtime_from_into_owned_string_routes_through_variant_slug_accessor`
3328 // (1e14fde) and
3329 // `caixa_arch::report::tests::arch_verdict_from_into_owned_string_routes_through_as_str_accessor`
3330 // (cc80a53) pins on the peer outside-`caixa-core` closed-set-
3331 // enum owned-`String`-returning axes — extends the trait-
3332 // idiomatic owned-`String`-returning forward-projection family
3333 // onto the sole closed-set fieldless typed enum on the caixa-
3334 // theme surface (the semantic-style 16-arm axis), extending
3335 // the substrate-wide 2×2-completion campaign onto the sixth
3336 // outside-`caixa-core` closed-set fieldless typed enum on the
3337 // caixa surface.
3338 for &variant in Semantic::ALL {
3339 let via_trait: String = <String as From<Semantic>>::from(variant);
3340 let via_method: &'static str = variant.as_str();
3341 assert_eq!(
3342 via_trait.as_str(),
3343 via_method,
3344 "From<Semantic> for String impl must round-trip \
3345 Semantic::{variant:?} to the same canonical-lowercase \
3346 kebab byte-string Semantic::as_str returns — \
3347 divergence signals a silent detour off the substrate-\
3348 primitive accessor"
3349 );
3350 let via_into: String = variant.into();
3351 assert_eq!(
3352 via_into.as_str(),
3353 via_method,
3354 "Into<String>::into on Semantic::{variant:?} must \
3355 byte-equal Semantic::as_str on the same input — the \
3356 blanket-derived Into shape must resolve to the same \
3357 as_str dispatch as the explicit From impl"
3358 );
3359 }
3360 }
3361
3362 #[test]
3363 fn semantic_from_into_owned_string_and_static_str_agree_on_every_arm() {
3364 // Cross-axis partition pin: the paired trait-idiomatic
3365 // owned-input `&'static str`-returning
3366 // `From<Semantic> for &'static str` and owned-`String`-
3367 // returning `From<Semantic> for String` (this lift) forward
3368 // projections must resolve identically on every arm, locking
3369 // the two output-shape paths together so any future detour (a
3370 // stray owned-`String` special-case that lands on a divergent
3371 // per-arm literal outside the paired `as_str` dispatch, a
3372 // hypothetical rebrand touching one axis without the other, a
3373 // silent swap onto a hand-rolled per-arm literal that shadows
3374 // the paired [`super::Semantic::as_str`] dispatch) trips at
3375 // caixa-theme test time. Then a witness that the
3376 // `ToString::to_string`-through-[`std::fmt::Display`] surface
3377 // (`variant.to_string()`) byte-equals the trait-idiomatic
3378 // owned-`String` axis (`String::from(variant)`) on every arm,
3379 // so a future consumer that reaches for `.to_string()` and
3380 // one that reaches for `.into::<String>()` land on the same
3381 // substrate-primitive vocabulary. Plus a
3382 // `.iter().copied().map(String::from)` pipe witness over
3383 // [`super::Semantic::ALL`] — the exact shape a future per-
3384 // Semantic histogram key materializer or `caixa-lsp` per-
3385 // `SemanticTokenType` registration walk reaches through —
3386 // materializes the 16-arm accept-set through the owned-
3387 // `String` axis alone. Plus a direct `Self → String → Self`
3388 // round-trip witness through the paired [`TryFrom<&str>`]
3389 // axis on the owned-`String`'s [`String::as_str`] borrow,
3390 // closing the two-way round-trip on the owned-`String` axis
3391 // directly (no wire-vocab intermediate — the emit-side
3392 // [`super::Semantic::as_str`] and the parse-side
3393 // [`super::Semantic::from_wire`] dispatch on the same 16
3394 // inline canonical-lowercase kebab byte-strings by
3395 // construction).
3396 //
3397 // Peer of the sibling
3398 // `caixa_provedor::ferrite::tests::ferrite_runtime_from_into_owned_string_and_static_str_agree_on_every_arm`
3399 // (1e14fde) partition pin on the peer outside-`caixa-core`
3400 // closed-set-enum owned-`String`-returning axis.
3401 for &variant in Semantic::ALL {
3402 let owned_string: String = <String as From<Semantic>>::from(variant);
3403 let owned_static: &'static str = <&'static str as From<Semantic>>::from(variant);
3404 assert_eq!(
3405 owned_string.as_str(),
3406 owned_static,
3407 "From<Semantic> for String and From<Semantic> for \
3408 &'static str must resolve identically on \
3409 Semantic::{variant:?} — divergence signals the two \
3410 output-shape forward-projection paths have drifted \
3411 onto different emit-sets"
3412 );
3413 let via_display: String = variant.to_string();
3414 assert_eq!(
3415 owned_string, via_display,
3416 "From<Semantic> for String and ToString::to_string \
3417 via Display must resolve identically on \
3418 Semantic::{variant:?} — divergence signals the \
3419 trait-idiomatic owned-`String` axis and the Display-\
3420 routed ToString axis have drifted onto different \
3421 vocabularies"
3422 );
3423 }
3424 let via_iter: Vec<String> = Semantic::ALL.iter().copied().map(String::from).collect();
3425 let via_method: Vec<String> = Semantic::ALL
3426 .iter()
3427 .map(|s| s.as_str().to_owned())
3428 .collect();
3429 assert_eq!(
3430 via_iter, via_method,
3431 "`.iter().copied().map(String::from)` over Semantic::ALL \
3432 must byte-equal `.iter().map(|s| s.as_str().to_owned())` \
3433 on every arm — the owned-`String` `From<Semantic> for \
3434 String` axis is what makes the `.map(String::from)` \
3435 shape route through the substrate-primitive \
3436 Semantic::as_str accessor rather than through a per-\
3437 call-site `.to_owned()` / `String::from(sem.as_str())` \
3438 detour"
3439 );
3440 for &variant in Semantic::ALL {
3441 let emitted: String = variant.into();
3442 let re_parsed: Result<Semantic, ()> =
3443 <Semantic as TryFrom<&str>>::try_from(emitted.as_str());
3444 assert_eq!(
3445 re_parsed,
3446 Ok(variant),
3447 "trait-idiomatic owned-`String` axis pair must round-\
3448 trip Semantic::{variant:?} through \
3449 `.into::<String>()` and back through `TryFrom<&str>` \
3450 on the owned-`String`'s `String::as_str` borrow — a \
3451 break signals the forward-emit owned-`String` axis \
3452 and the reverse-parse `TryFrom<&str>` axis have \
3453 drifted onto different vocabularies"
3454 );
3455 }
3456 }
3457
3458 #[test]
3459 fn semantic_from_borrowed_into_owned_string_routes_through_as_str_accessor() {
3460 // Fail-before-pass-after byte-parity pin on the newly lifted
3461 // `impl From<&Semantic> for String` — asserts the borrowed-
3462 // input owned-`String`-returning standard-library trait impl
3463 // and the substrate-primitive [`super::Semantic::as_str`]
3464 // `pub const fn` accessor resolve to the same 16-arm
3465 // canonical-lowercase kebab emit-set across every arm the
3466 // exhaustive [`super::Semantic::ALL`] slice enumerates.
3467 // Rust's standard library does not carry a blanket
3468 // `impl<T: AsRef<str>> From<&T> for String` (nor an
3469 // `impl<T: fmt::Display> From<&T> for String`), so the
3470 // borrowed-input owned-`String` forward-projection axis is a
3471 // distinct trait-idiomatic surface that a
3472 // `let key: String = (&sem).into();`-shaped call site
3473 // reaches through this impl and no other — the paired
3474 // sibling `From<Semantic> for String` impl (5ea146c) forces
3475 // every borrowed-input call site through an explicit `Copy`
3476 // deref (`String::from(*sem)`) or a `.as_str().to_owned()` /
3477 // `.to_string()` detour whose type bounds have no compile-
3478 // time link to the substrate primitive. Sweeps every one of
3479 // the 16 arms [`super::Semantic::ALL`] carries so no arm's
3480 // borrowed-input owned-`String` projection is covered only
3481 // by the sibling method-named `as_str` / [`std::fmt::Display`]
3482 // / [`AsRef<str>`] / owned-input `&'static str`-returning /
3483 // owned-input owned-`String`-returning paths.
3484 //
3485 // Peer of the sibling
3486 // `caixa_provedor::ferrite::tests::ferrite_runtime_from_borrowed_into_owned_string_routes_through_variant_slug_accessor`
3487 // (0caedec — fifth outside-`caixa-core` arm on this axis,
3488 // the paired ferrite-runtime two-arm axis on the sole caixa-
3489 // provedor closed-set enum) and
3490 // `caixa_lint::diagnostic::tests::fix_safety_from_borrowed_into_owned_string_routes_through_as_str_accessor`
3491 // (807f67d — fourth outside-`caixa-core` arm on this axis)
3492 // pins on the peer outside-`caixa-core` closed-set-enum
3493 // borrowed-input owned-`String`-returning axes — closes the
3494 // whole `{Self, &Self} × {&'static str, String}` 2×2 trait-
3495 // idiomatic projection corner on the sixth-and-last outside-
3496 // `caixa-core` closed-set fieldless typed enum on the caixa
3497 // surface (the caixa-theme semantic-style 16-arm axis every
3498 // per-Semantic paint dispatch, every future `caixa-lsp` per-
3499 // `SemanticTokenType` wire-up, every future `caixa.nvim`
3500 // per-highlight-group re-loader, and every future
3501 // `blackmatter-shell` per-arm `data-semantic="<kebab>"` DOM
3502 // emission keys off), and closes the substrate-wide 2×2-
3503 // completion campaign across every closed-set fieldless
3504 // typed enum on the caixa surface.
3505 for &variant in Semantic::ALL {
3506 let via_trait: String = <String as From<&Semantic>>::from(&variant);
3507 let via_method: &'static str = variant.as_str();
3508 assert_eq!(
3509 via_trait.as_str(),
3510 via_method,
3511 "From<&Semantic> for String impl must round-trip \
3512 &Semantic::{variant:?} to the same canonical-\
3513 lowercase kebab byte-string Semantic::as_str \
3514 returns — divergence signals a silent detour off \
3515 the substrate-primitive accessor"
3516 );
3517 let via_into: String = (&variant).into();
3518 assert_eq!(
3519 via_into.as_str(),
3520 via_method,
3521 "Into<String>::into on &Semantic::{variant:?} must \
3522 byte-equal Semantic::as_str on the same input — \
3523 the blanket-derived Into shape must resolve to the \
3524 same as_str dispatch as the explicit From impl"
3525 );
3526 }
3527 }
3528
3529 #[test]
3530 fn semantic_from_borrowed_into_owned_string_agrees_with_paired_axes_on_every_arm() {
3531 // Cross-axis partition pin: the newly lifted trait-
3532 // idiomatic borrowed-input owned-`String`
3533 // `From<&Semantic> for String` (this lift), the paired
3534 // owned-input owned-`String` `From<Semantic> for String`
3535 // (5ea146c), the paired borrowed-input owned-`&'static str`
3536 // `From<&Semantic> for &'static str` (ffc0f26), and the
3537 // paired owned-input owned-`&'static str`
3538 // `From<Semantic> for &'static str` — every corner of the
3539 // `{Self, &Self} × {&'static str, String}` 2×2 trait-
3540 // idiomatic projection family — must resolve identically on
3541 // every arm, locking the four return-shape × input-shape
3542 // paths together so any future detour trips at caixa-theme
3543 // test time. Also byte-parity witness against the sibling
3544 // [`ToString::to_string`] surface routed through
3545 // [`std::fmt::Display`] and a direct round-trip witness
3546 // through the paired trait-idiomatic reverse
3547 // [`TryFrom<&str>`] axis on the owned-`String`'s
3548 // [`String::as_str`] borrow that closes the two-way
3549 // `&Self → String → Self` round-trip on the trait-idiomatic
3550 // borrowed-input owned-`String` forward + reverse axis pair.
3551 //
3552 // The `.iter().map(String::from)` pipe witness over
3553 // [`super::Semantic::ALL`] materializes the exact shape a
3554 // future per-Semantic histogram key materializer or
3555 // `caixa-lsp` per-`SemanticTokenType` registration walk
3556 // reaches through — [`super::Semantic::ALL`]'s iterator
3557 // yields `&Semantic` by construction, so the borrowed-input
3558 // owned-`String` axis is what routes the pipe through the
3559 // substrate-primitive [`super::Semantic::as_str`] accessor
3560 // without a spurious `.copied()` / `Copy` deref (the paired
3561 // owned-input pipe witness on the sibling
3562 // `semantic_from_into_owned_string_and_static_str_agree_on_every_arm`
3563 // uses `.iter().copied().map(String::from)` for exactly this
3564 // reason — the owned-input axis alone cannot route the pipe
3565 // through the substrate primitive without the extra deref).
3566 //
3567 // Peer of the sibling
3568 // `caixa_provedor::ferrite::tests::ferrite_runtime_from_borrowed_into_owned_string_agrees_with_paired_axes_on_every_arm`
3569 // (0caedec — fifth outside-`caixa-core` arm on this axis)
3570 // partition pin on the peer outside-`caixa-core` closed-
3571 // set-enum borrowed-input owned-`String` axis — closes the
3572 // substrate-wide 2×2-completion campaign on the sixth-and-
3573 // last outside-`caixa-core` closed-set fieldless typed enum
3574 // on the caixa surface.
3575 for &variant in Semantic::ALL {
3576 let borrowed_string: String = <String as From<&Semantic>>::from(&variant);
3577 let owned_string: String = <String as From<Semantic>>::from(variant);
3578 let borrowed_static: &'static str = <&'static str as From<&Semantic>>::from(&variant);
3579 let owned_static: &'static str = <&'static str as From<Semantic>>::from(variant);
3580 assert_eq!(
3581 borrowed_string, owned_string,
3582 "From<&Semantic> for String and From<Semantic> for \
3583 String must resolve identically on \
3584 Semantic::{variant:?} — divergence signals the \
3585 owned-`String` axis pair's borrowed-input and \
3586 owned-input arms have drifted onto different emit-\
3587 sets"
3588 );
3589 assert_eq!(
3590 borrowed_string.as_str(),
3591 borrowed_static,
3592 "From<&Semantic> for String and From<&Semantic> for \
3593 &'static str must resolve identically on \
3594 Semantic::{variant:?} — divergence signals the \
3595 borrowed-input axis pair's owned-`String`-returning \
3596 and `&'static str`-returning arms have drifted \
3597 onto different emit-sets"
3598 );
3599 assert_eq!(
3600 borrowed_string.as_str(),
3601 owned_static,
3602 "From<&Semantic> for String and From<Semantic> for \
3603 &'static str must resolve identically on \
3604 Semantic::{variant:?} — the cross-diagonal corner \
3605 of the 2×2 must agree, or the four projections \
3606 have split into two vocabularies"
3607 );
3608 let via_display: String = variant.to_string();
3609 assert_eq!(
3610 borrowed_string, via_display,
3611 "From<&Semantic> for String and ToString::to_string \
3612 via Display must resolve identically on \
3613 Semantic::{variant:?} — divergence signals the \
3614 trait-idiomatic borrowed-input owned-`String` axis \
3615 and the Display-routed ToString axis have drifted \
3616 onto different vocabularies"
3617 );
3618 }
3619 let via_iter: Vec<String> = Semantic::ALL.iter().map(String::from).collect();
3620 let via_method: Vec<String> = Semantic::ALL
3621 .iter()
3622 .map(|sem| sem.as_str().to_owned())
3623 .collect();
3624 assert_eq!(
3625 via_iter, via_method,
3626 "`.iter().map(String::from)` over Semantic::ALL must \
3627 byte-equal `.iter().map(|sem| sem.as_str().to_owned())` \
3628 on every arm — the borrowed-input owned-`String` \
3629 `From<&Semantic> for String` axis is what makes the \
3630 `.map(String::from)` shape route through the substrate-\
3631 primitive Semantic::as_str accessor without a spurious \
3632 `.copied()` / `Copy` deref"
3633 );
3634 for &variant in Semantic::ALL {
3635 let emitted: String = (&variant).into();
3636 let re_parsed: Result<Semantic, ()> =
3637 <Semantic as TryFrom<&str>>::try_from(emitted.as_str());
3638 assert_eq!(
3639 re_parsed,
3640 Ok(variant),
3641 "trait-idiomatic borrowed-input owned-`String` axis \
3642 pair must round-trip Semantic::{variant:?} through \
3643 `(&variant).into::<String>()` and back through \
3644 `TryFrom<&str>` on the owned-`String`'s \
3645 `String::as_str` borrow — a break signals the \
3646 borrowed-input forward-emit owned-`String` axis \
3647 and the reverse-parse `TryFrom<&str>` axis have \
3648 drifted onto different vocabularies"
3649 );
3650 }
3651 }
3652
3653 #[test]
3654 fn semantic_from_into_static_cow_str_routes_through_as_str_accessor() {
3655 // Fail-before-pass-after byte-parity pin on the newly lifted
3656 // `impl From<Semantic> for std::borrow::Cow<'static, str>` —
3657 // asserts the standard-library trait impl and the substrate-
3658 // primitive [`super::Semantic::as_str`] `pub const fn`
3659 // accessor resolve to the same sixteen-arm canonical-
3660 // lowercase kebab emit-set (`"keyword"` / `"symbol"` /
3661 // `"keyword-arg"` / `"string"` / `"number"` / `"literal"` /
3662 // `"comment"` / `"accent"` / `"muted"` / `"error"` /
3663 // `"warning"` / `"info"` / `"hint"` / `"added"` /
3664 // `"removed"` / `"unchanged"`) across every arm the
3665 // exhaustive [`super::Semantic::ALL`] slice enumerates.
3666 // Rust's standard library does not carry a blanket
3667 // `impl<T: AsRef<str>> From<T> for std::borrow::Cow<'static, str>`
3668 // (nor an `impl<T: fmt::Display> From<T> for std::borrow::Cow<'static, str>`),
3669 // so the [`std::borrow::Cow<'static, str>`] forward-projection
3670 // axis is a distinct trait-idiomatic surface that a
3671 // `let key: std::borrow::Cow<'static, str> = sem.into();`-
3672 // shaped call site reaches through this impl and no other —
3673 // the paired sibling `From<Semantic> for &'static str` and
3674 // `From<Semantic> for String` impls force every
3675 // [`std::borrow::Cow<'static, str>`]-parameterized call site
3676 // through a `std::borrow::Cow::Borrowed(sem.as_str())` /
3677 // `std::borrow::Cow::Owned(sem.to_string())` /
3678 // `String::from(sem).into()` composition whose type bounds
3679 // have no compile-time link back to the substrate primitive.
3680 //
3681 // Also asserts the projection lands on the zero-alloc
3682 // [`std::borrow::Cow::Borrowed`] arm (not the
3683 // [`std::borrow::Cow::Owned`] arm) — the substrate-primitive
3684 // [`super::Semantic::as_str`] accessor's `&'static str`
3685 // return lifetime by construction makes the borrowed arm the
3686 // type-correct projection with no runtime allocation. Any
3687 // future silent detour that routes the impl through the
3688 // owned arm (an accidental
3689 // `std::borrow::Cow::Owned(sem.to_string())` rewrite that
3690 // would allocate on every call site where the `&'static str`
3691 // return of [`super::Semantic::as_str`] makes the zero-alloc
3692 // borrowed projection type-correct) trips at caixa-theme
3693 // test time under the [`std::borrow::Cow::Borrowed`]
3694 // discriminator witness rather than at a downstream
3695 // [`std::borrow::Cow<'static, str>`]-bound consumer's silent
3696 // allocation.
3697 //
3698 // Fifth outside-`caixa-core` peer (and sole peer on the
3699 // caixa-theme surface) on the substrate-wide trait-idiomatic
3700 // [`std::borrow::Cow<'static, str>`] forward-projection
3701 // family — extends the axis off the paired caixa-lint fix-
3702 // safety-tier axis on the sibling two-arm closed-set enum
3703 // ([`caixa_lint::diagnostic::FixSafety`], 79010c5 / 9a6539f
3704 // — fourth outside-`caixa-core` peer, closed the 2×3 corner)
3705 // onto the semantic-style sixteen-arm axis, continuing the
3706 // outside-`caixa-core` tier of the campaign.
3707 for &variant in Semantic::ALL {
3708 let via_trait: std::borrow::Cow<'static, str> =
3709 <std::borrow::Cow<'static, str> as From<Semantic>>::from(variant);
3710 let via_method: &'static str = variant.as_str();
3711 assert_eq!(
3712 via_trait.as_ref(),
3713 via_method,
3714 "From<Semantic> for Cow<'static, str> impl must round-\
3715 trip Semantic::{variant:?} to the same canonical-\
3716 lowercase kebab byte-string Semantic::as_str returns \
3717 — divergence signals a silent detour off the \
3718 substrate-primitive accessor"
3719 );
3720 assert!(
3721 matches!(via_trait, std::borrow::Cow::Borrowed(_)),
3722 "From<Semantic> for Cow<'static, str> impl must land \
3723 on the zero-alloc Cow::Borrowed arm on \
3724 Semantic::{variant:?} — a Cow::Owned outcome \
3725 signals the projection has silently allocated where \
3726 the substrate-primitive Semantic::as_str \
3727 `&'static str` return makes the borrowed arm the \
3728 type-correct projection"
3729 );
3730 let via_into: std::borrow::Cow<'static, str> = variant.into();
3731 assert_eq!(
3732 via_into.as_ref(),
3733 via_method,
3734 "Into<Cow<'static, str>>::into on \
3735 Semantic::{variant:?} must byte-equal \
3736 Semantic::as_str on the same input — the blanket-\
3737 derived Into shape must resolve to the same as_str \
3738 dispatch as the explicit From impl"
3739 );
3740 assert!(
3741 matches!(via_into, std::borrow::Cow::Borrowed(_)),
3742 "Into<Cow<'static, str>>::into on \
3743 Semantic::{variant:?} must land on the zero-alloc \
3744 Cow::Borrowed arm — the blanket-derived Into shape \
3745 must resolve to the same Cow::Borrowed dispatch as \
3746 the explicit From impl"
3747 );
3748 }
3749 }
3750
3751 #[test]
3752 fn semantic_from_into_static_cow_str_agrees_with_paired_axes_on_every_arm() {
3753 // Cross-axis partition pin: the newly lifted trait-idiomatic
3754 // `From<Semantic> for std::borrow::Cow<'static, str>` (this
3755 // lift), the paired owned-input
3756 // `From<Semantic> for &'static str`, and the paired owned-
3757 // input `From<Semantic> for String` forward projections must
3758 // resolve identically on every arm, locking the three return-
3759 // shape paths together by construction so any future detour
3760 // trips at caixa-theme test time. Also byte-parity witness
3761 // against the sibling [`ToString::to_string`] surface routed
3762 // through [`std::fmt::Display`] — every owned-heap-string
3763 // path (the [`std::borrow::Cow::Owned`] promotion of this
3764 // axis's `.into_owned()`, `From<Semantic> for String`, and
3765 // `.to_string()`) resolves to the same canonical-lowercase
3766 // kebab byte-string per arm.
3767 //
3768 // Then a `.iter().copied().map(std::borrow::Cow::from)` pipe
3769 // witness over [`super::Semantic::ALL`] that materializes
3770 // the sixteen-arm accept-set through the
3771 // [`std::borrow::Cow<'static, str>`] axis alone — the exact
3772 // shape a future `feira lint --list-styles` operator-facing
3773 // enumeration, a future `caixa-lsp`-side per-
3774 // `SemanticTokenType` registration table whose typing rules
3775 // out the sibling [`AsRef<str>`] borrowed return, or a
3776 // future `caixa.nvim` per-highlight-group re-loader table
3777 // reaches through — closing the composable-projection axis
3778 // on the caixa-theme semantic-style sixteen-arm closed-set
3779 // fieldless typed enum peer. The pipe witness also pins the
3780 // zero-alloc discipline: every element in the collected
3781 // vector satisfies the [`std::borrow::Cow::Borrowed`] arm
3782 // predicate, so a future accidental silent-allocation
3783 // regression on the pipe's iteration axis is a caixa-theme-
3784 // test-time failure.
3785 //
3786 // Then a direct round-trip witness through [`TryFrom<&str>`]
3787 // on the projection's [`std::borrow::Cow::as_ref`] borrow —
3788 // like the sibling [`caixa_lint::diagnostic::FixSafety`]
3789 // and [`caixa_lint::diagnostic::Severity`] pairs (whose
3790 // canonical-lowercase byte-strings are round-trip-stable),
3791 // and unlike the peer [`caixa_core::CaixaKind`] pair (whose
3792 // forward emit lands on the lowercase Portuguese diagnostic
3793 // vocabulary while the reverse parse lands on the
3794 // `PascalCase` wire vocabulary), [`super::Semantic`]'s
3795 // forward emit and reverse parse share the same sixteen
3796 // inline canonical-lowercase kebab byte-strings by
3797 // construction, so the [`std::borrow::Cow<'static, str>`]
3798 // projection composes directly with the trait-idiomatic
3799 // reverse [`TryFrom<&str>`] axis without the wire-vocab
3800 // intermediate hop.
3801 for &variant in Semantic::ALL {
3802 let via_cow: std::borrow::Cow<'static, str> =
3803 <std::borrow::Cow<'static, str> as From<Semantic>>::from(variant);
3804 let via_static: &'static str = <&'static str as From<Semantic>>::from(variant);
3805 let via_string: String = <String as From<Semantic>>::from(variant);
3806 assert_eq!(
3807 via_cow.as_ref(),
3808 via_static,
3809 "From<Semantic> for Cow<'static, str> and \
3810 From<Semantic> for &'static str must resolve \
3811 identically on Semantic::{variant:?} — divergence \
3812 signals the Cow<'static, str> and &'static str \
3813 return-shape paths have drifted onto different \
3814 emit-sets"
3815 );
3816 assert_eq!(
3817 via_cow.as_ref(),
3818 via_string.as_str(),
3819 "From<Semantic> for Cow<'static, str> and \
3820 From<Semantic> for String must resolve identically \
3821 on Semantic::{variant:?} — divergence signals the \
3822 Cow<'static, str> and String return-shape paths \
3823 have drifted onto different emit-sets"
3824 );
3825 let via_to_string: String = variant.to_string();
3826 assert_eq!(
3827 via_cow.as_ref(),
3828 via_to_string.as_str(),
3829 "From<Semantic> for Cow<'static, str> must byte-\
3830 equal Semantic::to_string on Semantic::{variant:?} \
3831 — divergence signals the trait-idiomatic \
3832 Cow<'static, str> forward-projection axis and the \
3833 ToString-through-Display axis have drifted onto \
3834 different emit-sets"
3835 );
3836 }
3837 let via_iter: Vec<std::borrow::Cow<'static, str>> = Semantic::ALL
3838 .iter()
3839 .copied()
3840 .map(std::borrow::Cow::from)
3841 .collect();
3842 let via_method: Vec<std::borrow::Cow<'static, str>> = Semantic::ALL
3843 .iter()
3844 .map(|sem| std::borrow::Cow::Borrowed(sem.as_str()))
3845 .collect();
3846 assert_eq!(
3847 via_iter, via_method,
3848 "`.iter().copied().map(Cow::from)` over Semantic::ALL \
3849 must byte-equal `.iter().map(|sem| \
3850 Cow::Borrowed(sem.as_str()))` on every arm — the trait-\
3851 idiomatic `From<Semantic> for Cow<'static, str>` axis \
3852 is what makes the `Cow::from` composition route through \
3853 the substrate-primitive Semantic::as_str accessor \
3854 rather than a per-call-site open-code"
3855 );
3856 for cow in &via_iter {
3857 assert!(
3858 matches!(cow, std::borrow::Cow::Borrowed(_)),
3859 "`.iter().copied().map(Cow::from)` over \
3860 Semantic::ALL must land on the zero-alloc \
3861 Cow::Borrowed arm on every element — a Cow::Owned \
3862 outcome signals the pipe has silently allocated \
3863 where the substrate-primitive Semantic::as_str \
3864 `&'static str` return makes the borrowed arm the \
3865 type-correct projection"
3866 );
3867 }
3868 for &variant in Semantic::ALL {
3869 let via_cow: std::borrow::Cow<'static, str> =
3870 <std::borrow::Cow<'static, str> as From<Semantic>>::from(variant);
3871 let re_parsed: Result<Semantic, ()> =
3872 <Semantic as TryFrom<&str>>::try_from(via_cow.as_ref());
3873 assert_eq!(
3874 re_parsed,
3875 Ok(variant),
3876 "trait-idiomatic Cow<'static, str> forward-projection \
3877 + reverse-projection axis pair must round-trip \
3878 Semantic::{variant:?} through \
3879 `.into::<Cow<'static, str>>()` on the owned-input \
3880 surface and back through `TryFrom<&str>` on the \
3881 projection's Cow::as_ref borrow — a break signals \
3882 the Cow<'static, str> forward-emit and reverse-\
3883 parse axes have drifted onto different vocabularies \
3884 (like the sibling FixSafety and Severity pairs, \
3885 Semantic's forward emit and reverse parse share \
3886 the same sixteen inline canonical-lowercase kebab \
3887 byte-strings by construction, so the round-trip \
3888 composes directly)"
3889 );
3890 }
3891 }
3892
3893 #[test]
3894 fn semantic_from_borrowed_into_static_cow_str_routes_through_as_str_accessor() {
3895 // Fail-before-pass-after byte-parity pin on the newly lifted
3896 // `impl From<&Semantic> for std::borrow::Cow<'static, str>` —
3897 // asserts the borrowed-input standard-library trait impl and
3898 // the substrate-primitive [`super::Semantic::as_str`]
3899 // `pub const fn` accessor resolve to the same sixteen-arm
3900 // canonical-lowercase kebab emit-set (`"keyword"` / `"symbol"` /
3901 // `"keyword-arg"` / `"string"` / `"number"` / `"literal"` /
3902 // `"comment"` / `"accent"` / `"muted"` / `"error"` /
3903 // `"warning"` / `"info"` / `"hint"` / `"added"` / `"removed"` /
3904 // `"unchanged"`) across every arm the exhaustive
3905 // [`super::Semantic::ALL`] slice enumerates. Rust's standard
3906 // library does not carry a blanket
3907 // `impl<T: AsRef<str>> From<&T> for Cow<'static, str>` (nor a
3908 // `Copy`-based `impl<T: Copy, U: From<T>> From<&T> for U`), so
3909 // the borrowed-input `Cow<'static, str>` forward-projection
3910 // axis is a distinct trait-idiomatic surface that a
3911 // `let key: Cow<'static, str> = (&sem).into();`-shaped call
3912 // site or a `Semantic::ALL.iter().map(Cow::from)`-shaped pipe
3913 // reaches through this impl and no other — the paired owned-
3914 // input `From<Semantic> for Cow<'static, str>` impl (0253688)
3915 // forces every borrowed-input call site through an explicit
3916 // `Copy` deref (`Cow::from(*sem)`) or a
3917 // `Cow::Borrowed(sem.as_str())` open-code whose type bounds
3918 // have no compile-time link back to the substrate primitive.
3919 //
3920 // Also asserts the projection lands on the zero-alloc
3921 // [`std::borrow::Cow::Borrowed`] arm (not the
3922 // [`std::borrow::Cow::Owned`] arm) — the substrate-primitive
3923 // [`super::Semantic::as_str`] accessor's `&'static str` return
3924 // lifetime by construction makes the borrowed arm the type-
3925 // correct projection with no runtime allocation on the
3926 // borrowed-input surface just as on the paired owned-input
3927 // surface.
3928 //
3929 // Closes the `{Self, &Self}` input-shape corner on the fifth
3930 // outside-`caixa-core` closed-set fieldless typed enum peer
3931 // of the substrate-wide [`std::borrow::Cow<'static, str>`]
3932 // forward-projection campaign, exactly as
3933 // `fix_safety_from_borrowed_into_static_cow_str_routes_through_as_str_accessor`
3934 // (9a6539f) closed it on the sibling caixa-lint
3935 // [`caixa_lint::diagnostic::FixSafety`] one commit after
3936 // (79010c5) closing the whole 2×3 corner,
3937 // `severity_from_borrowed_into_static_cow_str_routes_through_as_str_accessor`
3938 // (1819087) on [`caixa_lint::diagnostic::Severity`] one commit
3939 // after (700a95e) closing the whole 2×3 corner, and every
3940 // peer closer that preceded it on the campaign.
3941 for &variant in Semantic::ALL {
3942 let via_trait: std::borrow::Cow<'static, str> =
3943 <std::borrow::Cow<'static, str> as From<&Semantic>>::from(&variant);
3944 let via_method: &'static str = variant.as_str();
3945 assert_eq!(
3946 via_trait.as_ref(),
3947 via_method,
3948 "From<&Semantic> for Cow<'static, str> impl must \
3949 round-trip &Semantic::{variant:?} to the same \
3950 canonical-lowercase kebab byte-string \
3951 Semantic::as_str returns — divergence signals a \
3952 silent detour off the substrate-primitive accessor"
3953 );
3954 assert!(
3955 matches!(via_trait, std::borrow::Cow::Borrowed(_)),
3956 "From<&Semantic> for Cow<'static, str> impl must \
3957 land on the zero-alloc Cow::Borrowed arm on \
3958 &Semantic::{variant:?} — a Cow::Owned outcome \
3959 signals the projection has silently allocated where \
3960 the substrate-primitive Semantic::as_str \
3961 `&'static str` return makes the borrowed arm the \
3962 type-correct projection"
3963 );
3964 let via_into: std::borrow::Cow<'static, str> = (&variant).into();
3965 assert_eq!(
3966 via_into.as_ref(),
3967 via_method,
3968 "Into<Cow<'static, str>>::into on \
3969 &Semantic::{variant:?} must byte-equal \
3970 Semantic::as_str on the same input — the blanket-\
3971 derived Into shape on the borrowed-input surface \
3972 must resolve to the same as_str dispatch as the \
3973 explicit From impl"
3974 );
3975 assert!(
3976 matches!(via_into, std::borrow::Cow::Borrowed(_)),
3977 "Into<Cow<'static, str>>::into on \
3978 &Semantic::{variant:?} must land on the zero-alloc \
3979 Cow::Borrowed arm — the blanket-derived Into shape \
3980 on the borrowed-input surface must resolve to the \
3981 same Cow::Borrowed dispatch as the explicit From \
3982 impl"
3983 );
3984 }
3985 }
3986
3987 #[test]
3988 #[allow(
3989 clippy::too_many_lines,
3990 reason = "cross-axis partition pin folds four return-shape paths \
3991 (borrowed-input Cow<'static, str>, owned-input Cow<'static, str>, \
3992 borrowed-input &'static str, borrowed-input String) plus the \
3993 ToString-through-Display witness plus a `.iter().map(Cow::from)` \
3994 pipe witness with zero-alloc discriminator plus a direct \
3995 round-trip witness through TryFrom<&str> over sixteen typed \
3996 variants; the linear per-axis repetition is exactly what the \
3997 fold is pinning — a helper would hide the shape it locks"
3998 )]
3999 fn semantic_from_borrowed_into_static_cow_str_agrees_with_paired_axes_on_every_arm() {
4000 // Cross-axis partition pin: the newly lifted trait-idiomatic
4001 // borrowed-input `From<&Semantic> for
4002 // std::borrow::Cow<'static, str>` (this lift), the paired
4003 // owned-input `From<Semantic> for
4004 // std::borrow::Cow<'static, str>` (0253688), the paired
4005 // borrowed-input `From<&Semantic> for &'static str`, and the
4006 // paired borrowed-input `From<&Semantic> for String` forward
4007 // projections must resolve identically on every arm, locking
4008 // the four return-shape paths together by construction so any
4009 // future detour trips at caixa-theme test time. Also byte-
4010 // parity witness against the sibling [`ToString::to_string`]
4011 // surface routed through [`std::fmt::Display`].
4012 //
4013 // Then a `.iter().map(std::borrow::Cow::from)` pipe witness
4014 // over [`super::Semantic::ALL`] — whose iterator yields
4015 // `&Semantic` by construction, so the borrowed-input
4016 // [`std::borrow::Cow<'static, str>`] axis is what routes the
4017 // pipe through the substrate-primitive
4018 // [`super::Semantic::as_str`] accessor with the zero-alloc
4019 // [`std::borrow::Cow::Borrowed`] arm and without a spurious
4020 // [`Copy`] deref. Every collected element satisfies the
4021 // [`std::borrow::Cow::Borrowed`]-arm predicate so a future
4022 // accidental silent-allocation regression on the pipe's
4023 // iteration axis is a caixa-theme-test-time failure.
4024 //
4025 // Then a direct round-trip witness through [`TryFrom<&str>`]
4026 // on the projection's [`std::borrow::Cow::as_ref`] borrow —
4027 // unlike the peer [`caixa_core::CaixaKind`] axis pair (whose
4028 // forward emit lands on the lowercase Portuguese diagnostic
4029 // vocabulary while the reverse parse lands on the
4030 // `PascalCase` wire vocabulary, forcing the round-trip
4031 // through an intermediate [`caixa_core::CaixaKind::wire_name`]
4032 // hop), [`super::Semantic`]'s forward emit and reverse parse
4033 // share the same sixteen inline canonical-lowercase kebab
4034 // byte-strings by construction, so the borrowed-input
4035 // [`std::borrow::Cow<'static, str>`] projection composes
4036 // directly with the trait-idiomatic reverse [`TryFrom<&str>`]
4037 // axis without the wire-vocab intermediate hop.
4038 for &variant in Semantic::ALL {
4039 let via_borrowed_cow: std::borrow::Cow<'static, str> =
4040 <std::borrow::Cow<'static, str> as From<&Semantic>>::from(&variant);
4041 let via_owned_cow: std::borrow::Cow<'static, str> =
4042 <std::borrow::Cow<'static, str> as From<Semantic>>::from(variant);
4043 let via_borrowed_static: &'static str =
4044 <&'static str as From<&Semantic>>::from(&variant);
4045 let via_borrowed_string: String = <String as From<&Semantic>>::from(&variant);
4046 assert_eq!(
4047 via_borrowed_cow.as_ref(),
4048 via_owned_cow.as_ref(),
4049 "From<&Semantic> for Cow<'static, str> and \
4050 From<Semantic> for Cow<'static, str> must resolve \
4051 identically on Semantic::{variant:?} — divergence \
4052 signals the borrowed-input and owned-input \
4053 Cow<'static, str> forward-projection input-shape \
4054 paths have drifted onto different emit-sets"
4055 );
4056 assert_eq!(
4057 via_borrowed_cow.as_ref(),
4058 via_borrowed_static,
4059 "From<&Semantic> for Cow<'static, str> and \
4060 From<&Semantic> for &'static str must resolve \
4061 identically on Semantic::{variant:?} — divergence \
4062 signals the borrowed-input Cow<'static, str> and \
4063 borrowed-input `&'static str` return-shape paths \
4064 have drifted onto different emit-sets"
4065 );
4066 assert_eq!(
4067 via_borrowed_cow.as_ref(),
4068 via_borrowed_string.as_str(),
4069 "From<&Semantic> for Cow<'static, str> and \
4070 From<&Semantic> for String must resolve identically \
4071 on Semantic::{variant:?} — divergence signals the \
4072 borrowed-input Cow<'static, str> and borrowed-input \
4073 owned-`String` return-shape paths have drifted onto \
4074 different emit-sets"
4075 );
4076 let via_to_string: String = variant.to_string();
4077 assert_eq!(
4078 via_borrowed_cow.as_ref(),
4079 via_to_string.as_str(),
4080 "From<&Semantic> for Cow<'static, str> must byte-\
4081 equal Semantic::to_string on Semantic::{variant:?} \
4082 — divergence signals the trait-idiomatic borrowed-\
4083 input Cow<'static, str> forward-projection axis and \
4084 the ToString-through-Display axis have drifted onto \
4085 different emit-sets"
4086 );
4087 assert!(
4088 matches!(via_borrowed_cow, std::borrow::Cow::Borrowed(_)),
4089 "From<&Semantic> for Cow<'static, str> must land on \
4090 the zero-alloc Cow::Borrowed arm on \
4091 &Semantic::{variant:?} — a Cow::Owned outcome \
4092 signals the borrowed-input surface has silently \
4093 allocated where the substrate-primitive \
4094 Semantic::as_str `&'static str` return makes the \
4095 borrowed arm the type-correct projection"
4096 );
4097 }
4098 let via_iter: Vec<std::borrow::Cow<'static, str>> =
4099 Semantic::ALL.iter().map(std::borrow::Cow::from).collect();
4100 let via_method: Vec<std::borrow::Cow<'static, str>> = Semantic::ALL
4101 .iter()
4102 .map(|sem| std::borrow::Cow::Borrowed(sem.as_str()))
4103 .collect();
4104 assert_eq!(
4105 via_iter, via_method,
4106 "`.iter().map(Cow::from)` over Semantic::ALL — a call \
4107 site whose iteration axis holds `&Semantic` by \
4108 construction — must byte-equal `.iter().map(|sem| \
4109 Cow::Borrowed(sem.as_str()))` on every arm — the \
4110 borrowed-input `From<&Semantic> for Cow<'static, str>` \
4111 axis is what makes the `Cow::from` composition route \
4112 through the substrate-primitive `Semantic::as_str` \
4113 accessor without a spurious `Copy` deref (which would \
4114 only be reachable through the owned-input \
4115 `From<Semantic> for Cow<'static, str>` axis by first \
4116 calling `.copied()` on the iterator)"
4117 );
4118 for cow in &via_iter {
4119 assert!(
4120 matches!(cow, std::borrow::Cow::Borrowed(_)),
4121 "`.iter().map(Cow::from)` over Semantic::ALL must \
4122 land on the zero-alloc Cow::Borrowed arm on every \
4123 element — a Cow::Owned outcome signals the pipe has \
4124 silently allocated through the borrowed-input axis \
4125 where the substrate-primitive Semantic::as_str \
4126 `&'static str` return makes the borrowed arm the \
4127 type-correct projection"
4128 );
4129 }
4130 for &variant in Semantic::ALL {
4131 let via_cow: std::borrow::Cow<'static, str> =
4132 <std::borrow::Cow<'static, str> as From<&Semantic>>::from(&variant);
4133 let re_parsed: Result<Semantic, ()> =
4134 <Semantic as TryFrom<&str>>::try_from(via_cow.as_ref());
4135 assert_eq!(
4136 re_parsed,
4137 Ok(variant),
4138 "trait-idiomatic borrowed-input Cow<'static, str> \
4139 forward-projection + reverse-projection axis pair \
4140 must round-trip &Semantic::{variant:?} through \
4141 `(&variant).into::<Cow<'static, str>>()` on the \
4142 borrowed-input surface and back through \
4143 `TryFrom<&str>` on the projection's Cow::as_ref \
4144 borrow — a break signals the borrowed-input \
4145 Cow<'static, str> forward-emit and reverse-parse \
4146 axes have drifted onto different vocabularies \
4147 (unlike the peer CaixaKind axis pair, Semantic's \
4148 forward emit and reverse parse share the same \
4149 sixteen inline canonical-lowercase kebab byte-\
4150 strings by construction, so the round-trip composes \
4151 directly)"
4152 );
4153 }
4154 }
4155
4156 #[test]
4157 fn semantic_from_into_box_str_routes_through_as_str_accessor() {
4158 // Fail-before-pass-after byte-parity pin on the newly lifted
4159 // `impl From<Semantic> for Box<str>` — asserts the owned-input
4160 // standard-library trait impl and the substrate-primitive
4161 // [`super::Semantic::as_str`] `pub const fn` accessor resolve
4162 // to the same sixteen-arm canonical-lowercase kebab emit-set
4163 // across every arm the exhaustive [`super::Semantic::ALL`]
4164 // slice enumerates. Extends the outside-`caixa-core` tier of
4165 // the substrate-wide [`Box<str>`] forward-projection campaign
4166 // onto the fifth peer — the caixa-theme semantic-style
4167 // sixteen-arm closed-set fieldless typed enum — following the
4168 // first-mover [`caixa_arch::invariants::InvariantKind`] pair
4169 // (10613a7 owned + 5901887 borrowed), second-peer
4170 // [`caixa_arch::report::ArchVerdict`] pair (3e08f5a owned +
4171 // c4319a8 borrowed), third-peer [`super::Severity`] pair
4172 // (5116c95), and fourth-peer [`super::FixSafety`] pair
4173 // (cf0174b) that landed the tier one axis prior. Rust's
4174 // standard library carries `impl From<&str> for Box<str>` and
4175 // `impl From<String> for Box<str>` but no blanket
4176 // `impl<T: AsRef<str>> From<T> for Box<str>`, so this axis is
4177 // a distinct trait-idiomatic surface that a
4178 // `let key: Box<str> = sem.into();`-shaped call site reaches
4179 // through this impl and no other — a paired
4180 // `Box::from(sem.as_str())` open-code has no compile-time link
4181 // back to the substrate primitive.
4182 for &variant in Semantic::ALL {
4183 let via_trait: Box<str> = <Box<str> as From<Semantic>>::from(variant);
4184 let via_method: &'static str = variant.as_str();
4185 assert_eq!(
4186 via_trait.as_ref(),
4187 via_method,
4188 "From<Semantic> for Box<str> impl must round-trip \
4189 Semantic::{variant:?} to the same canonical-lowercase \
4190 kebab byte-string Semantic::as_str returns — \
4191 divergence signals a silent detour off the substrate-\
4192 primitive accessor"
4193 );
4194 let via_into: Box<str> = variant.into();
4195 assert_eq!(
4196 via_into.as_ref(),
4197 via_method,
4198 "Into<Box<str>>::into on Semantic::{variant:?} must \
4199 byte-equal Semantic::as_str on the same input — the \
4200 blanket-derived Into shape must resolve to the same \
4201 as_str dispatch as the explicit From impl"
4202 );
4203 }
4204 }
4205
4206 #[test]
4207 fn semantic_from_borrowed_into_box_str_routes_through_as_str_accessor() {
4208 // Fail-before-pass-after byte-parity pin on the newly lifted
4209 // `impl From<&Semantic> for Box<str>` — asserts the borrowed-
4210 // input standard-library trait impl and the substrate-
4211 // primitive [`super::Semantic::as_str`] `pub const fn`
4212 // accessor resolve to the same sixteen-arm canonical-lowercase
4213 // kebab emit-set across every arm the exhaustive
4214 // [`super::Semantic::ALL`] slice enumerates. Rust's standard
4215 // library carries `impl From<&str> for Box<str>` and
4216 // `impl From<String> for Box<str>` but no blanket
4217 // `impl<T: AsRef<str>> From<&T> for Box<str>` (nor a `Copy`-
4218 // based `impl<T: Copy, U: From<T>> From<&T> for U`), so the
4219 // borrowed-input [`Box<str>`] forward-projection axis is a
4220 // distinct trait-idiomatic surface that a
4221 // `Semantic::ALL.iter().map(Box::<str>::from)`-shaped pipe
4222 // (whose iterator over `&'static [Semantic]` yields
4223 // `&Semantic` by construction) or a `let key: Box<str> =
4224 // (&sem).into();`-shaped call site reaches through this impl
4225 // and no other — the paired owned-input
4226 // `From<Semantic> for Box<str>` impl alone would force every
4227 // borrowed-input call site through an explicit `Copy` deref
4228 // (`Box::<str>::from(*sem)`) or a
4229 // `Box::<str>::from(sem.as_str())` open-code whose type bounds
4230 // have no compile-time link back to the substrate primitive.
4231 //
4232 // Closes the `{Self, &Self}` input-shape corner on the fifth
4233 // outside-`caixa-core` closed-set fieldless typed enum peer of
4234 // the substrate-wide [`Box<str>`] forward-projection campaign,
4235 // exactly as 5901887 closed the paired first-mover
4236 // `InvariantKind` axis one commit after (10613a7) landed,
4237 // c4319a8 closed the paired second-peer `ArchVerdict` axis one
4238 // commit after (3e08f5a) landed, 5116c95 landed the paired
4239 // third-peer `Severity` pair one axis prior, cf0174b landed
4240 // the paired fourth-peer `FixSafety` pair one axis prior,
4241 // cb1d068 closed the paired M2-OTP-shape `RestartPolicy` axis
4242 // one commit after (0a1b313) landed, and 3c971b2 closed the
4243 // paired M3-mesh-shape `PlacementStrategy` axis one commit
4244 // after (6d73e84) landed.
4245 for &variant in Semantic::ALL {
4246 let via_trait: Box<str> = <Box<str> as From<&Semantic>>::from(&variant);
4247 let via_method: &'static str = variant.as_str();
4248 assert_eq!(
4249 via_trait.as_ref(),
4250 via_method,
4251 "From<&Semantic> for Box<str> impl must round-trip \
4252 &Semantic::{variant:?} to the same canonical-\
4253 lowercase kebab byte-string Semantic::as_str returns \
4254 — divergence signals a silent detour off the \
4255 substrate-primitive accessor"
4256 );
4257 let via_into: Box<str> = (&variant).into();
4258 assert_eq!(
4259 via_into.as_ref(),
4260 via_method,
4261 "Into<Box<str>>::into on &Semantic::{variant:?} must \
4262 byte-equal Semantic::as_str on the same input — the \
4263 blanket-derived Into shape on the borrowed-input \
4264 surface must resolve to the same as_str dispatch as \
4265 the explicit From impl"
4266 );
4267 }
4268
4269 // Pipe witness — the distinguishing shape that forces the
4270 // borrowed-input axis to be independent of the owned-input
4271 // peer. `Semantic::ALL.iter()` yields `&Semantic` by
4272 // construction, so `.map(Box::<str>::from)` resolves through
4273 // the borrowed-input `From<&Semantic> for Box<str>` impl and
4274 // no other — without this axis, the same pipe would force an
4275 // explicit `.copied()` restatement whose type bounds bypass
4276 // the substrate primitive.
4277 let via_pipe: Vec<Box<str>> = Semantic::ALL.iter().map(Box::<str>::from).collect();
4278 let via_accessor: Vec<&'static str> = Semantic::ALL.iter().map(|s| s.as_str()).collect();
4279 assert_eq!(
4280 via_pipe.len(),
4281 via_accessor.len(),
4282 "Semantic::ALL.iter().map(Box::<str>::from) pipe must \
4283 preserve arity against the paired Semantic::as_str \
4284 accessor — a length divergence signals the borrowed-input \
4285 axis has silently rejected an arm"
4286 );
4287 for (pipe_arm, accessor_arm) in via_pipe.iter().zip(via_accessor.iter()) {
4288 assert_eq!(
4289 pipe_arm.as_ref(),
4290 *accessor_arm,
4291 "Semantic::ALL.iter().map(Box::<str>::from) pipe must \
4292 byte-equal the paired Semantic::ALL.iter().map(|s| \
4293 s.as_str()) pipe on every arm — divergence signals \
4294 the borrowed-input `From<&Semantic> for Box<str>` \
4295 axis has silently detoured off the substrate-\
4296 primitive accessor"
4297 );
4298 }
4299 }
4300
4301 #[test]
4302 fn semantic_from_into_arc_str_routes_through_as_str_accessor() {
4303 // Fail-before-pass-after byte-parity pin on the newly lifted
4304 // `impl From<Semantic> for std::sync::Arc<str>` — asserts the
4305 // owned-input standard-library trait impl and the substrate-
4306 // primitive [`super::Semantic::as_str`] `pub const fn` accessor
4307 // resolve to the same sixteen-arm canonical-lowercase kebab
4308 // emit-set across every arm the exhaustive
4309 // [`super::Semantic::ALL`] slice enumerates. Extends the
4310 // outside-`caixa-core` tier of the substrate-wide
4311 // [`std::sync::Arc<str>`] forward-projection campaign onto the
4312 // fifth peer — the caixa-theme semantic-style sixteen-arm
4313 // closed-set fieldless typed enum — following the first-mover
4314 // [`caixa_arch::invariants::InvariantKind`] pair (4e923c1 owned
4315 // + 03c043f borrowed), second-peer
4316 // [`caixa_arch::report::ArchVerdict`] pair (1682f8b owned +
4317 // 92ddfb2 borrowed), third-peer `caixa_lint::diagnostic::Severity`
4318 // pair (a7a9a6d owned + 4f041e1 borrowed), and fourth-peer
4319 // `caixa_lint::diagnostic::FixSafety` pair (fb73edb owned +
4320 // 822138e borrowed) that landed the tier one axis prior.
4321 //
4322 // Rust's standard library carries `impl From<&str> for
4323 // std::sync::Arc<str>` and `impl From<String> for
4324 // std::sync::Arc<str>` but no blanket
4325 // `impl<T: AsRef<str>> From<T> for std::sync::Arc<str>` (nor
4326 // an `impl<T: fmt::Display> From<T> for std::sync::Arc<str>`),
4327 // so this axis is a distinct trait-idiomatic surface that a
4328 // `let key: std::sync::Arc<str> = sem.into();`-shaped call
4329 // site reaches through this impl and no other — a paired
4330 // `std::sync::Arc::<str>::from(sem.as_str())` open-code has
4331 // no compile-time link back to the substrate primitive, and a
4332 // two-step `std::sync::Arc::<str>::from(String::from(sem))`
4333 // composition through the owned-`String` axis allocates twice
4334 // (once into the intermediate `String`, once into the
4335 // [`std::sync::Arc<str>`] on the `From<String>` conversion)
4336 // where the single-step trait impl allocates once.
4337 //
4338 // Cross-axis byte-parity witness against the sibling owned-
4339 // input `{&'static str, String, Cow<'static, str>, Box<str>}`
4340 // return-shape axes — locking the five return-shape paths on
4341 // the owned-input surface together by construction so any
4342 // future detour off the substrate-primitive
4343 // [`super::Semantic::as_str`] accessor trips at caixa-theme
4344 // test time.
4345 for &variant in Semantic::ALL {
4346 let via_trait: std::sync::Arc<str> =
4347 <std::sync::Arc<str> as From<Semantic>>::from(variant);
4348 let via_method: &'static str = variant.as_str();
4349 assert_eq!(
4350 via_trait.as_ref(),
4351 via_method,
4352 "From<Semantic> for std::sync::Arc<str> impl must \
4353 round-trip Semantic::{variant:?} to the same \
4354 canonical-lowercase kebab byte-string Semantic::as_str \
4355 returns — divergence signals a silent detour off the \
4356 substrate-primitive accessor"
4357 );
4358 let via_into: std::sync::Arc<str> = variant.into();
4359 assert_eq!(
4360 via_into.as_ref(),
4361 via_method,
4362 "Into<std::sync::Arc<str>>::into on Semantic::\
4363 {variant:?} must byte-equal Semantic::as_str on the \
4364 same input — the blanket-derived Into shape must \
4365 resolve to the same as_str dispatch as the explicit \
4366 From impl"
4367 );
4368 let owned_static: &'static str = <&'static str as From<Semantic>>::from(variant);
4369 assert_eq!(
4370 via_trait.as_ref(),
4371 owned_static,
4372 "From<Semantic> for std::sync::Arc<str> and \
4373 From<Semantic> for &'static str must resolve \
4374 identically on Semantic::{variant:?} — divergence \
4375 signals the owned-input std::sync::Arc<str> and \
4376 &'static str return-shape paths have drifted onto \
4377 different emit-sets"
4378 );
4379 let owned_string: String = <String as From<Semantic>>::from(variant);
4380 assert_eq!(
4381 via_trait.as_ref(),
4382 owned_string.as_str(),
4383 "From<Semantic> for std::sync::Arc<str> and \
4384 From<Semantic> for String must resolve identically \
4385 on Semantic::{variant:?} — divergence signals the \
4386 owned-input std::sync::Arc<str> and owned-`String` \
4387 return-shape paths have drifted onto different \
4388 emit-sets"
4389 );
4390 let owned_cow: std::borrow::Cow<'static, str> =
4391 <std::borrow::Cow<'static, str> as From<Semantic>>::from(variant);
4392 assert_eq!(
4393 via_trait.as_ref(),
4394 owned_cow.as_ref(),
4395 "From<Semantic> for std::sync::Arc<str> and \
4396 From<Semantic> for Cow<'static, str> must resolve \
4397 identically on Semantic::{variant:?} — divergence \
4398 signals the owned-input std::sync::Arc<str> and \
4399 Cow<'static, str> return-shape paths have drifted \
4400 onto different emit-sets"
4401 );
4402 let owned_box: Box<str> = <Box<str> as From<Semantic>>::from(variant);
4403 assert_eq!(
4404 via_trait.as_ref(),
4405 owned_box.as_ref(),
4406 "From<Semantic> for std::sync::Arc<str> and \
4407 From<Semantic> for Box<str> must resolve identically \
4408 on Semantic::{variant:?} — divergence signals the \
4409 owned-input std::sync::Arc<str> and Box<str> \
4410 return-shape paths have drifted onto different \
4411 emit-sets"
4412 );
4413 }
4414 }
4415
4416 #[test]
4417 #[allow(
4418 clippy::too_many_lines,
4419 reason = "cross-axis partition pin folds four return-shape paths \
4420 (borrowed-input &'static str, String, Cow<'static, str>, \
4421 Box<str>) plus the paired owned-input Arc<str> witness \
4422 and the .iter().map(std::sync::Arc::<str>::from) pipe \
4423 witness into one exhaustive round-trip over \
4424 Semantic::ALL — the accepted line-count cost of keying \
4425 the whole borrowed-input Arc<str> corner to the \
4426 substrate-primitive as_str accessor at the same test-site"
4427 )]
4428 fn semantic_from_borrowed_into_arc_str_routes_through_as_str_accessor() {
4429 // Fail-before-pass-after byte-parity pin on the newly lifted
4430 // `impl From<&Semantic> for std::sync::Arc<str>` — asserts the
4431 // borrowed-input standard-library trait impl and the substrate-
4432 // primitive [`super::Semantic::as_str`] `pub const fn` accessor
4433 // resolve to the same sixteen-arm canonical-lowercase kebab
4434 // emit-set across every arm the exhaustive
4435 // [`super::Semantic::ALL`] slice enumerates. Rust's standard
4436 // library does not carry a blanket
4437 // `impl<T: AsRef<str>> From<&T> for std::sync::Arc<str>` (nor a
4438 // `Copy`-based `impl<T: Copy, U: From<T>> From<&T> for U`), so
4439 // the borrowed-input `std::sync::Arc<str>` forward-projection
4440 // axis is a distinct trait-idiomatic surface that a
4441 // `let key: std::sync::Arc<str> = (&sem).into();`-shaped call
4442 // site or a
4443 // `Semantic::ALL.iter().map(std::sync::Arc::<str>::from)`-shaped
4444 // pipe reaches through this impl and no other — the paired
4445 // owned-input `From<Semantic> for std::sync::Arc<str>` impl
4446 // (65dbcff) forces every borrowed-input call site through an
4447 // explicit `Copy` deref
4448 // (`std::sync::Arc::<str>::from((*sem).as_str())`) or a
4449 // `std::sync::Arc::<str>::from(sem.as_str())` open-code whose
4450 // type bounds have no compile-time link back to the substrate
4451 // primitive.
4452 //
4453 // Closes the `{Self, &Self}` input-shape corner on the fifth
4454 // peer of the outside-`caixa-core` tier of the substrate-wide
4455 // trait-idiomatic [`std::sync::Arc<str>`] forward-projection
4456 // campaign, exactly as 03c043f closed the paired first-mover
4457 // [`caixa_arch::invariants::InvariantKind`] `{Self, &Self}`
4458 // corner (4e923c1 owned + 03c043f borrowed) on this tier,
4459 // 92ddfb2 closed the paired second-peer
4460 // [`caixa_arch::report::ArchVerdict`] `{Self, &Self}` corner
4461 // (1682f8b owned + 92ddfb2 borrowed) on this tier, 4f041e1
4462 // closed the paired third-peer `caixa_lint::diagnostic::Severity`
4463 // `{Self, &Self}` corner (a7a9a6d owned + 4f041e1 borrowed) on
4464 // this tier, and 822138e closed the paired fourth-peer
4465 // `caixa_lint::diagnostic::FixSafety` `{Self, &Self}` corner
4466 // (fb73edb owned + 822138e borrowed) on this tier.
4467 //
4468 // Also byte-parity witness against the paired owned-input
4469 // [`From<Semantic> for std::sync::Arc<str>`] and the sibling
4470 // borrowed-input [`From<&Semantic> for &'static str`],
4471 // [`From<&Semantic> for String`],
4472 // [`From<&Semantic> for Cow<'static, str>`], and
4473 // [`From<&Semantic> for Box<str>`] return-shape axes — locking
4474 // the five return-shape × input-shape paths together by
4475 // construction so any future detour off the substrate-primitive
4476 // accessor trips at caixa-theme test time. Then a
4477 // `.iter().map(std::sync::Arc::<str>::from)` pipe witness over
4478 // [`super::Semantic::ALL`] — whose iterator yields `&Semantic`
4479 // by construction, so the borrowed-input
4480 // [`std::sync::Arc<str>`] axis is what routes the pipe through
4481 // the substrate-primitive [`super::Semantic::as_str`] accessor
4482 // without a spurious [`Copy`] deref (which would only be
4483 // reachable through the owned-input
4484 // [`From<Semantic> for std::sync::Arc<str>`] axis by first
4485 // calling `.copied()` on the iterator).
4486 for &variant in Semantic::ALL {
4487 let via_trait: std::sync::Arc<str> =
4488 <std::sync::Arc<str> as From<&Semantic>>::from(&variant);
4489 let via_method: &'static str = variant.as_str();
4490 assert_eq!(
4491 via_trait.as_ref(),
4492 via_method,
4493 "From<&Semantic> for std::sync::Arc<str> impl must \
4494 round-trip &Semantic::{variant:?} to the same \
4495 canonical-lowercase kebab byte-string Semantic::as_str \
4496 returns — divergence signals a silent detour off the \
4497 substrate-primitive accessor"
4498 );
4499 let via_into: std::sync::Arc<str> = (&variant).into();
4500 assert_eq!(
4501 via_into.as_ref(),
4502 via_method,
4503 "Into<std::sync::Arc<str>>::into on &Semantic::\
4504 {variant:?} must byte-equal Semantic::as_str on the \
4505 same input — the blanket-derived Into shape must \
4506 resolve to the same as_str dispatch as the explicit \
4507 From impl"
4508 );
4509 let owned_arc: std::sync::Arc<str> =
4510 <std::sync::Arc<str> as From<Semantic>>::from(variant);
4511 assert_eq!(
4512 via_trait, owned_arc,
4513 "From<&Semantic> for std::sync::Arc<str> and \
4514 From<Semantic> for std::sync::Arc<str> must resolve \
4515 identically on Semantic::{variant:?} — divergence \
4516 signals the borrowed-input and owned-input \
4517 std::sync::Arc<str> forward-projection input-shape \
4518 paths have drifted onto different emit-sets"
4519 );
4520 let borrowed_static: &'static str = <&'static str as From<&Semantic>>::from(&variant);
4521 assert_eq!(
4522 via_trait.as_ref(),
4523 borrowed_static,
4524 "From<&Semantic> for std::sync::Arc<str> and \
4525 From<&Semantic> for &'static str must resolve \
4526 identically on Semantic::{variant:?} — divergence \
4527 signals the borrowed-input std::sync::Arc<str> and \
4528 &'static str return-shape paths have drifted onto \
4529 different emit-sets"
4530 );
4531 let borrowed_string: String = <String as From<&Semantic>>::from(&variant);
4532 assert_eq!(
4533 via_trait.as_ref(),
4534 borrowed_string.as_str(),
4535 "From<&Semantic> for std::sync::Arc<str> and \
4536 From<&Semantic> for String must resolve identically \
4537 on Semantic::{variant:?} — divergence signals the \
4538 borrowed-input std::sync::Arc<str> and owned-`String` \
4539 return-shape paths have drifted onto different \
4540 emit-sets"
4541 );
4542 let borrowed_cow: std::borrow::Cow<'static, str> =
4543 <std::borrow::Cow<'static, str> as From<&Semantic>>::from(&variant);
4544 assert_eq!(
4545 via_trait.as_ref(),
4546 borrowed_cow.as_ref(),
4547 "From<&Semantic> for std::sync::Arc<str> and \
4548 From<&Semantic> for Cow<'static, str> must resolve \
4549 identically on Semantic::{variant:?} — divergence \
4550 signals the borrowed-input std::sync::Arc<str> and \
4551 Cow<'static, str> return-shape paths have drifted \
4552 onto different emit-sets"
4553 );
4554 let borrowed_box: Box<str> = <Box<str> as From<&Semantic>>::from(&variant);
4555 assert_eq!(
4556 via_trait.as_ref(),
4557 borrowed_box.as_ref(),
4558 "From<&Semantic> for std::sync::Arc<str> and \
4559 From<&Semantic> for Box<str> must resolve identically \
4560 on Semantic::{variant:?} — divergence signals the \
4561 borrowed-input std::sync::Arc<str> and Box<str> \
4562 return-shape paths have drifted onto different \
4563 emit-sets"
4564 );
4565 }
4566 // Pipe witness — the distinguishing shape that forces the
4567 // borrowed-input axis to be independent of the owned-input
4568 // peer. `Semantic::ALL.iter()` yields `&Semantic` by
4569 // construction, so `.map(std::sync::Arc::<str>::from)` resolves
4570 // through the borrowed-input
4571 // `From<&Semantic> for std::sync::Arc<str>` impl and no other —
4572 // without this axis, the same pipe would force an explicit
4573 // `.copied()` restatement whose type bounds bypass the
4574 // substrate primitive.
4575 let via_pipe: Vec<std::sync::Arc<str>> = Semantic::ALL
4576 .iter()
4577 .map(std::sync::Arc::<str>::from)
4578 .collect();
4579 let via_accessor: Vec<&'static str> = Semantic::ALL.iter().map(|s| s.as_str()).collect();
4580 assert_eq!(
4581 via_pipe.len(),
4582 via_accessor.len(),
4583 "Semantic::ALL.iter().map(std::sync::Arc::<str>::from) pipe \
4584 must preserve arity against the paired \
4585 Semantic::ALL.iter().map(|s| s.as_str()) accessor pipe — \
4586 a length divergence signals the borrowed-input axis has \
4587 silently rejected an arm"
4588 );
4589 for (pipe_arm, accessor_arm) in via_pipe.iter().zip(via_accessor.iter()) {
4590 assert_eq!(
4591 pipe_arm.as_ref(),
4592 *accessor_arm,
4593 "Semantic::ALL.iter().map(std::sync::Arc::<str>::from) \
4594 pipe must byte-equal the paired \
4595 Semantic::ALL.iter().map(|s| s.as_str()) pipe on every \
4596 arm — divergence signals the borrowed-input \
4597 `From<&Semantic> for std::sync::Arc<str>` axis has \
4598 silently detoured off the substrate-primitive accessor"
4599 );
4600 }
4601 }
4602
4603 #[test]
4604 fn semantic_from_into_rc_str_routes_through_as_str_accessor() {
4605 // Fail-before-pass-after byte-parity pin on the newly lifted
4606 // `impl From<Semantic> for std::rc::Rc<str>` — asserts the
4607 // owned-input standard-library trait impl and the substrate-
4608 // primitive [`super::Semantic::as_str`] `pub const fn`
4609 // accessor resolve to the same sixteen-arm canonical-lowercase
4610 // kebab emit-set across every arm the exhaustive
4611 // [`super::Semantic::ALL`] slice enumerates. Extends the
4612 // outside-`caixa-core` tier of the substrate-wide
4613 // [`std::rc::Rc<str>`] forward-projection campaign onto its
4614 // fifth peer — the caixa-theme semantic-style sixteen-arm
4615 // closed-set fieldless typed enum — following the first-mover
4616 // `caixa_arch::invariants::InvariantKind` pair (c71818b),
4617 // second-peer `caixa_arch::report::ArchVerdict` pair (cc759ef),
4618 // third-peer `caixa_lint::diagnostic::Severity` pair (d7c58b6),
4619 // and fourth-peer `caixa_lint::diagnostic::FixSafety` pair
4620 // (046cc5f) that landed the tier one axis prior.
4621 //
4622 // Rust's standard library carries `impl From<&str> for
4623 // std::rc::Rc<str>` and `impl From<String> for std::rc::Rc<str>`
4624 // but no blanket `impl<T: AsRef<str>> From<T> for
4625 // std::rc::Rc<str>`, and the [`std::sync::Arc<str>`] and
4626 // [`std::rc::Rc<str>`] trait tables are disjoint, so this axis
4627 // is a distinct trait-idiomatic surface that a
4628 // `let key: std::rc::Rc<str> = sem.into();`-shaped call site
4629 // reaches through this impl and no other — a paired
4630 // `std::rc::Rc::<str>::from(sem.as_str())` open-code has no
4631 // compile-time link back to the substrate primitive.
4632 //
4633 // Cross-axis byte-parity witness against the sibling owned-
4634 // input `{&'static str, String, Cow<'static, str>, Box<str>,
4635 // std::sync::Arc<str>}` return-shape axes — locking the six
4636 // return-shape paths on the owned-input surface together by
4637 // construction so any future detour off the substrate-
4638 // primitive [`super::Semantic::as_str`] accessor trips at
4639 // caixa-theme test time.
4640 for &variant in Semantic::ALL {
4641 let via_trait: std::rc::Rc<str> = <std::rc::Rc<str> as From<Semantic>>::from(variant);
4642 let via_method: &'static str = variant.as_str();
4643 assert_eq!(
4644 via_trait.as_ref(),
4645 via_method,
4646 "From<Semantic> for std::rc::Rc<str> impl must \
4647 round-trip Semantic::{variant:?} to the same \
4648 canonical-lowercase kebab byte-string Semantic::as_str \
4649 returns — divergence signals a silent detour off the \
4650 substrate-primitive accessor"
4651 );
4652 let via_into: std::rc::Rc<str> = variant.into();
4653 assert_eq!(
4654 via_into.as_ref(),
4655 via_method,
4656 "Into<std::rc::Rc<str>>::into on Semantic::{variant:?} \
4657 must byte-equal Semantic::as_str on the same input — \
4658 the blanket-derived Into shape must resolve to the \
4659 same as_str dispatch as the explicit From impl"
4660 );
4661 let owned_static: &'static str = <&'static str as From<Semantic>>::from(variant);
4662 assert_eq!(
4663 via_trait.as_ref(),
4664 owned_static,
4665 "From<Semantic> for std::rc::Rc<str> and From<Semantic> \
4666 for &'static str must resolve identically on \
4667 Semantic::{variant:?} — divergence signals the owned-\
4668 input std::rc::Rc<str> and &'static str return-shape \
4669 paths have drifted onto different emit-sets"
4670 );
4671 let owned_string: String = <String as From<Semantic>>::from(variant);
4672 assert_eq!(
4673 via_trait.as_ref(),
4674 owned_string.as_str(),
4675 "From<Semantic> for std::rc::Rc<str> and From<Semantic> \
4676 for String must resolve identically on \
4677 Semantic::{variant:?} — divergence signals the owned-\
4678 input std::rc::Rc<str> and owned-`String` return-shape \
4679 paths have drifted onto different emit-sets"
4680 );
4681 let owned_cow: std::borrow::Cow<'static, str> =
4682 <std::borrow::Cow<'static, str> as From<Semantic>>::from(variant);
4683 assert_eq!(
4684 via_trait.as_ref(),
4685 owned_cow.as_ref(),
4686 "From<Semantic> for std::rc::Rc<str> and From<Semantic> \
4687 for Cow<'static, str> must resolve identically on \
4688 Semantic::{variant:?} — divergence signals the owned-\
4689 input std::rc::Rc<str> and Cow<'static, str> return-\
4690 shape paths have drifted onto different emit-sets"
4691 );
4692 let owned_box: Box<str> = <Box<str> as From<Semantic>>::from(variant);
4693 assert_eq!(
4694 via_trait.as_ref(),
4695 owned_box.as_ref(),
4696 "From<Semantic> for std::rc::Rc<str> and From<Semantic> \
4697 for Box<str> must resolve identically on \
4698 Semantic::{variant:?} — divergence signals the owned-\
4699 input std::rc::Rc<str> and Box<str> return-shape paths \
4700 have drifted onto different emit-sets"
4701 );
4702 let owned_arc: std::sync::Arc<str> =
4703 <std::sync::Arc<str> as From<Semantic>>::from(variant);
4704 assert_eq!(
4705 via_trait.as_ref(),
4706 owned_arc.as_ref(),
4707 "From<Semantic> for std::rc::Rc<str> and From<Semantic> \
4708 for std::sync::Arc<str> must resolve identically on \
4709 Semantic::{variant:?} — divergence signals the owned-\
4710 input std::rc::Rc<str> and std::sync::Arc<str> return-\
4711 shape paths have drifted onto different emit-sets (the \
4712 two disjoint reference-counted trait tables have \
4713 desynchronized on the caixa-theme semantic-style axis)"
4714 );
4715 }
4716 }
4717
4718 #[test]
4719 #[allow(
4720 clippy::too_many_lines,
4721 reason = "cross-axis partition pin folds five borrowed-input \
4722 return-shape paths (&'static str, String, Cow<'static, \
4723 str>, Box<str>, std::sync::Arc<str>) plus the paired \
4724 owned-input Rc<str> witness and the \
4725 .iter().map(std::rc::Rc::<str>::from) pipe witness into \
4726 one exhaustive round-trip over Semantic::ALL — the \
4727 accepted line-count cost of keying the whole borrowed-\
4728 input Rc<str> corner to the substrate-primitive as_str \
4729 accessor at the same test-site"
4730 )]
4731 fn semantic_from_borrowed_into_rc_str_routes_through_as_str_accessor() {
4732 // Fail-before-pass-after byte-parity pin on the newly lifted
4733 // `impl From<&Semantic> for std::rc::Rc<str>` — asserts the
4734 // borrowed-input standard-library trait impl and the substrate-
4735 // primitive [`super::Semantic::as_str`] `pub const fn`
4736 // accessor resolve to the same sixteen-arm canonical-lowercase
4737 // kebab emit-set across every arm the exhaustive
4738 // [`super::Semantic::ALL`] slice enumerates. Rust's standard
4739 // library does not carry a blanket
4740 // `impl<T: AsRef<str>> From<&T> for std::rc::Rc<str>` (nor a
4741 // `Copy`-based `impl<T: Copy, U: From<T>> From<&T> for U`), so
4742 // the borrowed-input `std::rc::Rc<str>` forward-projection axis
4743 // is a distinct trait-idiomatic surface that a
4744 // `let key: std::rc::Rc<str> = (&sem).into();`-shaped call site
4745 // or a
4746 // `Semantic::ALL.iter().map(std::rc::Rc::<str>::from)`-shaped
4747 // pipe reaches through this impl and no other — the paired
4748 // owned-input `From<Semantic> for std::rc::Rc<str>` impl forces
4749 // every borrowed-input call site through an explicit `Copy`
4750 // deref (`std::rc::Rc::<str>::from((*sem).as_str())`) or a
4751 // `std::rc::Rc::<str>::from(sem.as_str())` open-code whose type
4752 // bounds have no compile-time link back to the substrate
4753 // primitive.
4754 //
4755 // Closes the `{Self, &Self}` input-shape corner on the fifth
4756 // peer of the outside-`caixa-core` tier of the substrate-wide
4757 // trait-idiomatic [`std::rc::Rc<str>`] forward-projection
4758 // campaign, matching the trajectory the paired
4759 // [`caixa_core::CaixaKind`] (e04aff0),
4760 // [`caixa_core::CaixaDialeto`] (c5595e5),
4761 // [`caixa_core::aplicacao::PlacementStrategy`] (91b4c92),
4762 // `caixa_arch::invariants::InvariantKind` (c71818b),
4763 // `caixa_arch::report::ArchVerdict` (cc759ef),
4764 // `caixa_lint::diagnostic::Severity` (d7c58b6),
4765 // `caixa_lint::diagnostic::FixSafety` (046cc5f),
4766 // `caixa_core::render::PathShapeViolation` (31fc43e), and
4767 // `caixa_core::dep::DepList` (38f6a3a) pairs walked before it
4768 // on the caixa-core-internal, M3-mesh-primitive-defining,
4769 // render-side, and outside-`caixa-core` tiers of the same axis.
4770 //
4771 // Also byte-parity witness against the paired owned-input
4772 // [`From<Semantic> for std::rc::Rc<str>`] and the sibling
4773 // borrowed-input [`From<&Semantic> for &'static str`],
4774 // [`From<&Semantic> for String`],
4775 // [`From<&Semantic> for Cow<'static, str>`],
4776 // [`From<&Semantic> for Box<str>`], and
4777 // [`From<&Semantic> for std::sync::Arc<str>`] return-shape
4778 // axes — locking the six return-shape × input-shape paths
4779 // together by construction so any future detour off the
4780 // substrate-primitive accessor trips at caixa-theme test time.
4781 // Then a `.iter().map(std::rc::Rc::<str>::from)` pipe witness
4782 // over [`super::Semantic::ALL`] — whose iterator yields
4783 // `&Semantic` by construction, so the borrowed-input
4784 // [`std::rc::Rc<str>`] axis is what routes the pipe through
4785 // the substrate-primitive [`super::Semantic::as_str`] accessor
4786 // without a spurious [`Copy`] deref.
4787 for &variant in Semantic::ALL {
4788 let via_trait: std::rc::Rc<str> = <std::rc::Rc<str> as From<&Semantic>>::from(&variant);
4789 let via_method: &'static str = variant.as_str();
4790 assert_eq!(
4791 via_trait.as_ref(),
4792 via_method,
4793 "From<&Semantic> for std::rc::Rc<str> impl must \
4794 round-trip &Semantic::{variant:?} to the same \
4795 canonical-lowercase kebab byte-string Semantic::as_str \
4796 returns — divergence signals a silent detour off the \
4797 substrate-primitive accessor"
4798 );
4799 let via_into: std::rc::Rc<str> = (&variant).into();
4800 assert_eq!(
4801 via_into.as_ref(),
4802 via_method,
4803 "Into<std::rc::Rc<str>>::into on &Semantic::{variant:?} \
4804 must byte-equal Semantic::as_str on the same input — \
4805 the blanket-derived Into shape must resolve to the \
4806 same as_str dispatch as the explicit From impl"
4807 );
4808 let owned_rc: std::rc::Rc<str> = <std::rc::Rc<str> as From<Semantic>>::from(variant);
4809 assert_eq!(
4810 via_trait, owned_rc,
4811 "From<&Semantic> for std::rc::Rc<str> and From<Semantic> \
4812 for std::rc::Rc<str> must resolve identically on \
4813 Semantic::{variant:?} — divergence signals the \
4814 borrowed-input and owned-input std::rc::Rc<str> \
4815 forward-projection input-shape paths have drifted onto \
4816 different emit-sets"
4817 );
4818 let borrowed_static: &'static str = <&'static str as From<&Semantic>>::from(&variant);
4819 assert_eq!(
4820 via_trait.as_ref(),
4821 borrowed_static,
4822 "From<&Semantic> for std::rc::Rc<str> and From<&Semantic> \
4823 for &'static str must resolve identically on \
4824 Semantic::{variant:?} — divergence signals the \
4825 borrowed-input std::rc::Rc<str> and &'static str \
4826 return-shape paths have drifted onto different \
4827 emit-sets"
4828 );
4829 let borrowed_string: String = <String as From<&Semantic>>::from(&variant);
4830 assert_eq!(
4831 via_trait.as_ref(),
4832 borrowed_string.as_str(),
4833 "From<&Semantic> for std::rc::Rc<str> and From<&Semantic> \
4834 for String must resolve identically on \
4835 Semantic::{variant:?} — divergence signals the \
4836 borrowed-input std::rc::Rc<str> and owned-`String` \
4837 return-shape paths have drifted onto different \
4838 emit-sets"
4839 );
4840 let borrowed_cow: std::borrow::Cow<'static, str> =
4841 <std::borrow::Cow<'static, str> as From<&Semantic>>::from(&variant);
4842 assert_eq!(
4843 via_trait.as_ref(),
4844 borrowed_cow.as_ref(),
4845 "From<&Semantic> for std::rc::Rc<str> and From<&Semantic> \
4846 for Cow<'static, str> must resolve identically on \
4847 Semantic::{variant:?} — divergence signals the \
4848 borrowed-input std::rc::Rc<str> and Cow<'static, str> \
4849 return-shape paths have drifted onto different \
4850 emit-sets"
4851 );
4852 let borrowed_box: Box<str> = <Box<str> as From<&Semantic>>::from(&variant);
4853 assert_eq!(
4854 via_trait.as_ref(),
4855 borrowed_box.as_ref(),
4856 "From<&Semantic> for std::rc::Rc<str> and From<&Semantic> \
4857 for Box<str> must resolve identically on \
4858 Semantic::{variant:?} — divergence signals the \
4859 borrowed-input std::rc::Rc<str> and Box<str> return-\
4860 shape paths have drifted onto different emit-sets"
4861 );
4862 let borrowed_arc: std::sync::Arc<str> =
4863 <std::sync::Arc<str> as From<&Semantic>>::from(&variant);
4864 assert_eq!(
4865 via_trait.as_ref(),
4866 borrowed_arc.as_ref(),
4867 "From<&Semantic> for std::rc::Rc<str> and From<&Semantic> \
4868 for std::sync::Arc<str> must resolve identically on \
4869 Semantic::{variant:?} — divergence signals the \
4870 borrowed-input std::rc::Rc<str> and std::sync::Arc<str> \
4871 return-shape paths have drifted onto different emit-\
4872 sets (the two disjoint reference-counted trait tables \
4873 have desynchronized on the caixa-theme semantic-style \
4874 axis under the borrowed-input corner)"
4875 );
4876 }
4877 // Pipe witness — the distinguishing shape that forces the
4878 // borrowed-input axis to be independent of the owned-input
4879 // peer. `Semantic::ALL.iter()` yields `&Semantic` by
4880 // construction, so `.map(std::rc::Rc::<str>::from)` resolves
4881 // through the borrowed-input
4882 // `From<&Semantic> for std::rc::Rc<str>` impl and no other —
4883 // without this axis, the same pipe would force an explicit
4884 // `.copied()` restatement whose type bounds bypass the
4885 // substrate primitive.
4886 let via_pipe: Vec<std::rc::Rc<str>> =
4887 Semantic::ALL.iter().map(std::rc::Rc::<str>::from).collect();
4888 let via_accessor: Vec<&'static str> = Semantic::ALL.iter().map(|s| s.as_str()).collect();
4889 assert_eq!(
4890 via_pipe.len(),
4891 via_accessor.len(),
4892 "Semantic::ALL.iter().map(std::rc::Rc::<str>::from) pipe \
4893 must preserve arity against the paired \
4894 Semantic::ALL.iter().map(|s| s.as_str()) accessor pipe — a \
4895 length divergence signals the borrowed-input axis has \
4896 silently rejected an arm"
4897 );
4898 for (pipe_arm, accessor_arm) in via_pipe.iter().zip(via_accessor.iter()) {
4899 assert_eq!(
4900 pipe_arm.as_ref(),
4901 *accessor_arm,
4902 "Semantic::ALL.iter().map(std::rc::Rc::<str>::from) pipe \
4903 must byte-equal the paired \
4904 Semantic::ALL.iter().map(|s| s.as_str()) pipe on every \
4905 arm — divergence signals the borrowed-input \
4906 `From<&Semantic> for std::rc::Rc<str>` axis has \
4907 silently detoured off the substrate-primitive accessor"
4908 );
4909 }
4910 }
4911
4912 #[test]
4913 fn semantic_wire_names_covers_every_arm() {
4914 // Load-bearing pin on the substrate-canonical
4915 // [`super::Semantic::WIRE_NAMES`] exhaustive accept-set roster
4916 // on the caixa-theme semantic-style lowercase-kebab wire-form
4917 // axis: every variant of the sibling [`super::Semantic::ALL`]
4918 // exhaustive-iteration surface must project through
4919 // [`super::Semantic::as_str`] onto an entry the
4920 // [`super::Semantic::WIRE_NAMES`] roster carries, and the
4921 // roster's length must byte-equal `super::Semantic::ALL.len()`
4922 // so a silent skew between the [`super::Semantic::as_str`]
4923 // match's arm-set and the roster's arm-set trips here at
4924 // caixa-theme test time rather than at a downstream
4925 // `feira lint --list-styles` per-arm listing / `caixa-lsp`
4926 // per-`SemanticTokenType` registration walk / `caixa.nvim`
4927 // per-highlight-group re-loader / `blackmatter-shell` per-arm
4928 // `data-semantic="<kebab>"` DOM-attribute emit drift.
4929 //
4930 // A future arm addition (a `Namespace` tier between
4931 // [`super::Semantic::Symbol`] and [`super::Semantic::KeywordArg`]
4932 // for the M4 tatara-lisp module system's qualified-name
4933 // semantic-token dispatch, a `Deleted` tier for a hard-delete-
4934 // mark distinct from [`super::Semantic::Removed`] the future
4935 // 3-way diff surface grows — both trajectory items the sibling
4936 // [`super::Semantic::ALL`] doc block already names) extends
4937 // [`super::Semantic::ALL`] as a single edit and this pin sweeps
4938 // the new arm by iteration; the paired
4939 // [`super::Semantic::WIRE_NAMES`] roster must grow in lockstep
4940 // or this assertion trips. Every entry is further pinned to
4941 // open with a lowercase ASCII byte (matching the substrate-wide
4942 // lowercase-tag convention every peer closed-set enum whose
4943 // canonical projection is a lowercase-tag byte-string carries),
4944 // so a silent collapse of the caixa-theme semantic-style axis
4945 // with any hypothetical PascalCase peer wire-form axis (an
4946 // entry byte-identical to the Debug-derived
4947 // `"Keyword"` / `"Symbol"` / `"KeywordArg"` / … shapes that
4948 // would let a wire-axis consumer accept the source-side variant
4949 // identifier) trips here rather than at a downstream theme-
4950 // overlay round-trip miss.
4951 //
4952 // Peer of the sibling
4953 // [`caixa_core::kind::tests::caixa_kind_wire_names_covers_every_arm`]
4954 // (bd708bd),
4955 // [`caixa_core::supervisor::tests::restart_strategy_wire_names_covers_every_arm`]
4956 // (3033f45),
4957 // [`caixa_core::supervisor::tests::restart_policy_wire_names_covers_every_arm`]
4958 // (ce9412b),
4959 // [`caixa_core::aplicacao::tests::placement_strategy_wire_names_covers_every_arm`]
4960 // (3e5b194),
4961 // [`caixa_core::render::tests::path_shape_violation_wire_names_covers_every_arm`]
4962 // (0330bd3),
4963 // [`caixa_core::dialeto::tests::caixa_dialeto_wire_names_covers_every_arm`]
4964 // (0402726),
4965 // `caixa_arch::invariants::tests::invariant_kind_wire_names_covers_every_arm`
4966 // (78f5522),
4967 // `caixa_arch::report::tests::arch_verdict_wire_names_covers_every_arm`
4968 // (ebddef0),
4969 // `caixa_lint::diagnostic::tests::severity_wire_names_covers_every_arm`
4970 // (a199462), and
4971 // `caixa_lint::diagnostic::tests::fix_safety_wire_names_covers_every_arm`
4972 // (5837236) pins — the same closed-set exhaustive-roster
4973 // coverage discipline extended here onto the *fifth outside*-
4974 // caixa-core closed-set fieldless typed enum on the caixa
4975 // surface (the caixa-theme semantic-style axis, and the first
4976 // inside `caixa-theme`).
4977 //
4978 // Fail-before-pass-after locally verified by mutating one arm
4979 // of the paired `CAIXA_THEME_SEMANTIC_WIRE_*` const family
4980 // (e.g. rebranding `CAIXA_THEME_SEMANTIC_WIRE_KEYWORD` from
4981 // `"keyword"` to `"kw"`) — the length pin still passes but the
4982 // `contains` check fires on the mutated arm; and by shortening
4983 // the roster to one entry — the length pin fires first.
4984 assert_eq!(
4985 super::Semantic::WIRE_NAMES.len(),
4986 super::Semantic::ALL.len(),
4987 "Semantic::WIRE_NAMES.len() must byte-equal \
4988 Semantic::ALL.len() — a mismatch means the roster and \
4989 the enum's arm-set have drifted; downstream consumers \
4990 that fan through both will silently disagree on the \
4991 accepted arm-set"
4992 );
4993 for &variant in super::Semantic::ALL {
4994 let wire = variant.as_str();
4995 assert!(
4996 super::Semantic::WIRE_NAMES.contains(&wire),
4997 "Semantic::{variant:?}.as_str() = {wire:?} must be a \
4998 member of Semantic::WIRE_NAMES — the emitter and the \
4999 roster have drifted out of lockstep"
5000 );
5001 }
5002 for tag in super::Semantic::WIRE_NAMES {
5003 let first = tag.chars().next().unwrap_or_else(|| {
5004 panic!(
5005 "Semantic::WIRE_NAMES entry {tag:?} must be a \
5006 non-empty lowercase-tag byte-string"
5007 )
5008 });
5009 assert!(
5010 first.is_ascii_lowercase(),
5011 "Semantic::WIRE_NAMES entry {tag:?} must open with a \
5012 lowercase ASCII byte (matching the substrate-wide \
5013 lowercase-tag convention every peer closed-set enum \
5014 whose canonical projection is a lowercase-tag byte-\
5015 string carries) — an entry opening with an uppercase \
5016 byte would collide the roster with any hypothetical \
5017 peer PascalCase wire-form axis a downstream consumer \
5018 might disambiguate against (the Debug-derived \
5019 `\"Keyword\"` / `\"Symbol\"` / `\"KeywordArg\"` / … \
5020 shapes)"
5021 );
5022 }
5023 // Pin the exact sixteen-arm roster in declaration order so a
5024 // future arm-swap on either the roster or the paired
5025 // `CAIXA_THEME_SEMANTIC_WIRE_*` constants (a rebrand of the
5026 // arm-tag mapping that leaves both the length pin and the
5027 // membership pin passing on their own) trips at caixa-theme
5028 // test time under `assert_eq!`. Order matches variant
5029 // declaration order verbatim (`Keyword` → `Symbol` →
5030 // `KeywordArg` → `String` → `Number` → `Literal` → `Comment` →
5031 // `Accent` → `Muted` → `Error` → `Warning` → `Info` → `Hint` →
5032 // `Added` → `Removed` → `Unchanged`) so the roster is the
5033 // canonical semantic-style ordering every listing / rendering
5034 // consumer defers to.
5035 assert_eq!(
5036 super::Semantic::WIRE_NAMES,
5037 &[
5038 super::CAIXA_THEME_SEMANTIC_WIRE_KEYWORD,
5039 super::CAIXA_THEME_SEMANTIC_WIRE_SYMBOL,
5040 super::CAIXA_THEME_SEMANTIC_WIRE_KEYWORD_ARG,
5041 super::CAIXA_THEME_SEMANTIC_WIRE_STRING,
5042 super::CAIXA_THEME_SEMANTIC_WIRE_NUMBER,
5043 super::CAIXA_THEME_SEMANTIC_WIRE_LITERAL,
5044 super::CAIXA_THEME_SEMANTIC_WIRE_COMMENT,
5045 super::CAIXA_THEME_SEMANTIC_WIRE_ACCENT,
5046 super::CAIXA_THEME_SEMANTIC_WIRE_MUTED,
5047 super::CAIXA_THEME_SEMANTIC_WIRE_ERROR,
5048 super::CAIXA_THEME_SEMANTIC_WIRE_WARNING,
5049 super::CAIXA_THEME_SEMANTIC_WIRE_INFO,
5050 super::CAIXA_THEME_SEMANTIC_WIRE_HINT,
5051 super::CAIXA_THEME_SEMANTIC_WIRE_ADDED,
5052 super::CAIXA_THEME_SEMANTIC_WIRE_REMOVED,
5053 super::CAIXA_THEME_SEMANTIC_WIRE_UNCHANGED,
5054 ],
5055 "Semantic::WIRE_NAMES must enumerate every arm's wire-form \
5056 tag exactly once, in variant declaration order (Keyword → \
5057 Symbol → KeywordArg → String → Number → Literal → Comment \
5058 → Accent → Muted → Error → Warning → Info → Hint → Added \
5059 → Removed → Unchanged)"
5060 );
5061 // Byte-parity pin on the paired reverse projection: every
5062 // entry in the roster must round-trip cleanly through
5063 // [`super::Semantic::from_wire`] back to the same arm the
5064 // [`super::Semantic::as_str`] emitter returned it for.
5065 // Refuses any future de-lift that swaps the sixteen consts
5066 // through the reverse projection out of lockstep with the
5067 // forward emitter (a mid-arm rebrand touching only `as_str`
5068 // but not `from_wire`, an argument-ordering swap on one of
5069 // the match arms, a stray `to_lowercase` normalization on
5070 // either side that would silently pass the identity round-trip
5071 // on the already-lowercase corpus but split the two
5072 // projections on any future non-lowercase input).
5073 for (&variant, tag) in super::Semantic::ALL.iter().zip(super::Semantic::WIRE_NAMES) {
5074 assert_eq!(
5075 super::Semantic::from_wire(tag),
5076 Some(variant),
5077 "Semantic::from_wire({tag:?}) must round-trip back to \
5078 Semantic::{variant:?} — emitter and parser have \
5079 drifted off the paired CAIXA_THEME_SEMANTIC_WIRE_* \
5080 const family"
5081 );
5082 }
5083 }
5084
5085 #[test]
5086 #[allow(
5087 clippy::too_many_lines,
5088 reason = "cross-axis partition pin folds the substrate-primitive \
5089 as_str accessor's `.as_bytes()` byte-tail plus the \
5090 paired str-view (AsRef<str>, Display, as_str) and \
5091 reverse-projection ({&'static str, String, Cow<'static, \
5092 str>, Box<str>, std::sync::Arc<str>, std::rc::Rc<str>}) \
5093 return-shape axes' `.as_bytes()` byte-tails plus a \
5094 <T: AsRef<[u8]>>-bound-consumer witness plus a \
5095 blake3::Hasher::update-shape byte-input surface witness \
5096 into one exhaustive round-trip over Semantic::ALL — \
5097 the accepted line-count cost of extending the byte-view \
5098 axis keyed to the substrate-primitive as_str accessor \
5099 at the same test-site"
5100 )]
5101 #[allow(
5102 clippy::needless_borrows_for_generic_args,
5103 reason = "the borrowed-input surface (&variant) is exercised \
5104 deliberately: the `<T: AsRef<[u8]>>`-bound consumer and \
5105 the `blake3::Hasher::update`-shape byte-input surface \
5106 both accept either owned or borrowed input through the \
5107 standard-library blanket `impl<T: ?Sized + AsRef<[u8]>> \
5108 AsRef<[u8]> for &T`, and this pin round-trips both \
5109 input shapes to lock the borrowed-input path load-\
5110 bearing against a future silent regression"
5111 )]
5112 fn semantic_as_ref_bytes_routes_through_as_str_accessor() {
5113 // `<T: AsRef<[u8]>>`-bound-consumer witness helper: a generic
5114 // byte-input function accepts a [`super::Semantic`] directly
5115 // through the trait bound, without the caller open-coding the
5116 // two-hop `sem.as_str().as_bytes()` composition. Lifted to the
5117 // top of the function per `clippy::items_after_statements`.
5118 fn generic_bytes_sink<T: AsRef<[u8]>>(t: T) -> Vec<u8> {
5119 t.as_ref().to_vec()
5120 }
5121 // `blake3::Hasher::update`-shape byte-input surface mock: mirrors
5122 // `blake3::Hasher::update` / `ring::digest::Context::update` /
5123 // `sha2::Sha256::update`'s `impl AsRef<[u8]>`-bound `update`
5124 // signature so a future per-theme BLAKE3 content-address closure
5125 // that composes `hasher.update(sem)` on the audit-log closure
5126 // builder reaches the substrate-primitive `as_str` accessor
5127 // through the [`super::Semantic`] `AsRef<[u8]>` axis and no
5128 // other.
5129 struct MockHasher(Vec<u8>);
5130 impl MockHasher {
5131 fn new() -> Self {
5132 Self(Vec::new())
5133 }
5134 fn update(&mut self, bytes: impl AsRef<[u8]>) -> &mut Self {
5135 self.0.extend_from_slice(bytes.as_ref());
5136 self
5137 }
5138 fn finalize(self) -> Vec<u8> {
5139 self.0
5140 }
5141 }
5142
5143 for &variant in super::Semantic::ALL {
5144 let via_trait: &[u8] = <super::Semantic as AsRef<[u8]>>::as_ref(&variant);
5145 let via_method_bytes: &[u8] = variant.as_str().as_bytes();
5146 assert_eq!(
5147 via_trait, via_method_bytes,
5148 "AsRef<[u8]> for Semantic impl must byte-equal \
5149 Semantic::as_str().as_bytes() on \
5150 Semantic::{variant:?} — divergence signals a silent \
5151 detour off the substrate-primitive accessor"
5152 );
5153 // Cross-axis witness against the paired str-view axes'
5154 // `.as_bytes()` byte-tails.
5155 let via_as_ref_str: &str = <super::Semantic as AsRef<str>>::as_ref(&variant);
5156 assert_eq!(
5157 via_trait,
5158 via_as_ref_str.as_bytes(),
5159 "AsRef<[u8]> for Semantic and AsRef<str> for Semantic \
5160 `.as_bytes()` must byte-equal on Semantic::{variant:?}"
5161 );
5162 let via_display: String = format!("{variant}");
5163 assert_eq!(
5164 via_trait,
5165 via_display.as_bytes(),
5166 "AsRef<[u8]> for Semantic and \
5167 std::fmt::Display::fmt::<Semantic> `.as_bytes()` must \
5168 byte-equal on Semantic::{variant:?}"
5169 );
5170 let via_as_str: &'static str = variant.as_str();
5171 assert_eq!(
5172 via_trait,
5173 via_as_str.as_bytes(),
5174 "AsRef<[u8]> for Semantic and Semantic::as_str \
5175 `.as_bytes()` must byte-equal on Semantic::{variant:?}"
5176 );
5177 // Cross-axis witness against the paired reverse-projection
5178 // axes' `.as_bytes()` byte-tails.
5179 let via_static: &'static str = <&'static str>::from(variant);
5180 assert_eq!(
5181 via_trait,
5182 via_static.as_bytes(),
5183 "AsRef<[u8]> for Semantic and From<Semantic> for \
5184 &'static str `.as_bytes()` must byte-equal on \
5185 Semantic::{variant:?}"
5186 );
5187 let via_string: String = String::from(variant);
5188 assert_eq!(
5189 via_trait,
5190 via_string.as_bytes(),
5191 "AsRef<[u8]> for Semantic and From<Semantic> for \
5192 String `.as_bytes()` must byte-equal on \
5193 Semantic::{variant:?}"
5194 );
5195 let via_cow: std::borrow::Cow<'static, str> =
5196 std::borrow::Cow::<'static, str>::from(variant);
5197 assert_eq!(
5198 via_trait,
5199 via_cow.as_bytes(),
5200 "AsRef<[u8]> for Semantic and From<Semantic> for \
5201 Cow<'static, str> `.as_bytes()` must byte-equal on \
5202 Semantic::{variant:?}"
5203 );
5204 let via_box: Box<str> = Box::<str>::from(variant);
5205 assert_eq!(
5206 via_trait,
5207 via_box.as_bytes(),
5208 "AsRef<[u8]> for Semantic and From<Semantic> for \
5209 Box<str> `.as_bytes()` must byte-equal on \
5210 Semantic::{variant:?}"
5211 );
5212 let atomic_shared: std::sync::Arc<str> = std::sync::Arc::<str>::from(variant);
5213 assert_eq!(
5214 via_trait,
5215 atomic_shared.as_bytes(),
5216 "AsRef<[u8]> for Semantic and From<Semantic> for \
5217 std::sync::Arc<str> `.as_bytes()` must byte-equal on \
5218 Semantic::{variant:?}"
5219 );
5220 let single_thread_shared: std::rc::Rc<str> = std::rc::Rc::<str>::from(variant);
5221 assert_eq!(
5222 via_trait,
5223 single_thread_shared.as_bytes(),
5224 "AsRef<[u8]> for Semantic and From<Semantic> for \
5225 std::rc::Rc<str> `.as_bytes()` must byte-equal on \
5226 Semantic::{variant:?}"
5227 );
5228 // `<T: AsRef<[u8]>>`-bound-consumer witness on both owned
5229 // and borrowed input surfaces.
5230 let via_generic_owned = generic_bytes_sink(variant);
5231 assert_eq!(
5232 via_trait, via_generic_owned,
5233 "generic `<T: AsRef<[u8]>>`-bound consumer on the \
5234 owned-input surface must byte-equal the substrate-\
5235 primitive as_str accessor's byte-tail on \
5236 Semantic::{variant:?}"
5237 );
5238 let via_generic_borrowed = generic_bytes_sink(&variant);
5239 assert_eq!(
5240 via_trait, via_generic_borrowed,
5241 "generic `<T: AsRef<[u8]>>`-bound consumer on the \
5242 borrowed-input surface must byte-equal the substrate-\
5243 primitive as_str accessor's byte-tail on \
5244 Semantic::{variant:?}"
5245 );
5246 // `blake3::Hasher::update`-shape byte-input surface witness
5247 // on both owned and borrowed input surfaces — the primary
5248 // compounding target on the byte-view axis is the caixa-
5249 // lacre BLAKE3 content-address closure, which binds its
5250 // input through exactly this trait bound.
5251 let mut hasher_owned_input = MockHasher::new();
5252 hasher_owned_input.update(variant);
5253 let owned_digest = hasher_owned_input.finalize();
5254 assert_eq!(
5255 owned_digest.as_slice(),
5256 via_trait,
5257 "blake3::Hasher::update-shape byte-input surface on the \
5258 owned-input surface must byte-equal the substrate-\
5259 primitive as_str accessor's byte-tail on \
5260 Semantic::{variant:?}"
5261 );
5262 let mut hasher_borrowed_input = MockHasher::new();
5263 hasher_borrowed_input.update(&variant);
5264 let borrowed_digest = hasher_borrowed_input.finalize();
5265 assert_eq!(
5266 borrowed_digest.as_slice(),
5267 via_trait,
5268 "blake3::Hasher::update-shape byte-input surface on the \
5269 borrowed-input surface must byte-equal the substrate-\
5270 primitive as_str accessor's byte-tail on \
5271 Semantic::{variant:?}"
5272 );
5273 }
5274 }
5275
5276 #[test]
5277 #[allow(
5278 clippy::too_many_lines,
5279 reason = "cross-axis partition pin folds the substrate-primitive \
5280 as_str accessor's `.as_bytes().to_vec()` byte-tail plus \
5281 the paired AsRef<[u8]> borrowed byte-view axis and the \
5282 str-owned reverse-projection family's `.into_bytes()` / \
5283 `.as_bytes().to_vec()` byte-tails plus a \
5284 <T: Into<Vec<u8>>>-bound-consumer witness plus a \
5285 std::io::Write::write_all-shape owned-byte-sink surface \
5286 witness plus a Debug-derive rejection witness into one \
5287 exhaustive round-trip over Semantic::ALL — the accepted \
5288 line-count cost of extending the byte-owned reverse-\
5289 projection axis keyed to the substrate-primitive as_str \
5290 accessor at the same test-site"
5291 )]
5292 fn semantic_from_into_owned_vec_bytes_routes_through_as_str_accessor() {
5293 // `<T: Into<Vec<u8>>>`-bound-consumer witness helper: a generic
5294 // owned-byte-input function accepts a [`super::Semantic`] directly
5295 // through the trait bound, without the caller open-coding the
5296 // three-hop `semantic.as_str().as_bytes().to_vec()` composition.
5297 // Lifted to the top of the function per
5298 // `clippy::items_after_statements`.
5299 fn generic_owned_bytes_sink<T: Into<Vec<u8>>>(t: T) -> Vec<u8> {
5300 t.into()
5301 }
5302 // `std::io::Write::write_all`-shape owned-byte-sink surface mock:
5303 // mirrors `std::io::Write::write_all` /
5304 // `bytes::BytesMut::extend_from_slice` / any per-theme audit-log
5305 // byte-sink that consumes a `Vec<u8>` payload via
5306 // `Into<Vec<u8>>`, so a future per-theme audit-log emit reaches
5307 // the substrate-primitive `as_str` accessor through the byte-
5308 // owned reverse-projection axis and no other. Lifted to the top
5309 // of the function per `clippy::items_after_statements`.
5310 struct MockOwnedByteSink(Vec<u8>);
5311 impl MockOwnedByteSink {
5312 fn new() -> Self {
5313 Self(Vec::new())
5314 }
5315 fn write_all(&mut self, bytes: impl Into<Vec<u8>>) -> &mut Self {
5316 self.0.extend_from_slice(&bytes.into());
5317 self
5318 }
5319 fn finalize(self) -> Vec<u8> {
5320 self.0
5321 }
5322 }
5323
5324 for &variant in super::Semantic::ALL {
5325 let via_owned_from: Vec<u8> = <Vec<u8> as From<super::Semantic>>::from(variant);
5326 let via_borrowed_from: Vec<u8> = <Vec<u8> as From<&super::Semantic>>::from(&variant);
5327 let via_method_bytes: Vec<u8> = variant.as_str().as_bytes().to_vec();
5328 assert_eq!(
5329 via_owned_from, via_method_bytes,
5330 "From<Semantic> for Vec<u8> impl must byte-equal \
5331 Semantic::as_str().as_bytes().to_vec() on \
5332 Semantic::{variant:?} — divergence signals a silent \
5333 detour off the substrate-primitive accessor"
5334 );
5335 assert_eq!(
5336 via_borrowed_from, via_method_bytes,
5337 "From<&Semantic> for Vec<u8> impl must byte-equal \
5338 Semantic::as_str().as_bytes().to_vec() on \
5339 Semantic::{variant:?} — divergence signals a silent \
5340 detour off the substrate-primitive accessor"
5341 );
5342 assert_eq!(
5343 via_owned_from, via_borrowed_from,
5344 "From<Semantic> for Vec<u8> and From<&Semantic> for \
5345 Vec<u8> must byte-equal each other on \
5346 Semantic::{variant:?} — divergence signals the owned-\
5347 input and borrowed-input paths have drifted off the \
5348 same substrate-primitive as_str accessor"
5349 );
5350 // Cross-axis witness against the paired [`AsRef<[u8]>`]
5351 // borrowed byte-view axis (2c58220): the byte-owned reverse-
5352 // projection axis must byte-equal the paired borrowed byte-
5353 // view axis by construction — locking the byte-view and
5354 // byte-owned axes together at the substrate-primitive
5355 // accessor.
5356 let borrowed_bytes: &[u8] = <super::Semantic as AsRef<[u8]>>::as_ref(&variant);
5357 assert_eq!(
5358 via_owned_from,
5359 borrowed_bytes.to_vec(),
5360 "From<Semantic> for Vec<u8> and AsRef<[u8]> for Semantic \
5361 must resolve to byte-equal byte-tails on \
5362 Semantic::{variant:?} — divergence signals the byte-\
5363 owned and byte-view axes have drifted off the same \
5364 substrate-primitive as_str accessor"
5365 );
5366 // Cross-axis witness against the str-owned reverse-
5367 // projection family's `.into_bytes()` / `.as_bytes().to_vec()`
5368 // byte-tails: every one of `{String, Cow<'static, str>,
5369 // Box<str>, std::sync::Arc<str>, std::rc::Rc<str>}` allocates
5370 // (or borrows) the same sixteen-arm canonical-lowercase
5371 // kebab byte-string the substrate-primitive accessor emits,
5372 // so the byte-owned axis must byte-equal each of their owned
5373 // byte-tails by construction.
5374 let owned_string: String = <String as From<super::Semantic>>::from(variant);
5375 assert_eq!(
5376 via_owned_from,
5377 owned_string.into_bytes(),
5378 "From<Semantic> for Vec<u8> and \
5379 String::from(semantic).into_bytes() must resolve to \
5380 byte-equal byte-tails on Semantic::{variant:?}"
5381 );
5382 let owned_cow: std::borrow::Cow<'static, str> =
5383 <std::borrow::Cow<'static, str> as From<super::Semantic>>::from(variant);
5384 assert_eq!(
5385 via_owned_from,
5386 owned_cow.as_bytes().to_vec(),
5387 "From<Semantic> for Vec<u8> and From<Semantic> for \
5388 Cow<'static, str> must resolve to byte-equal byte-\
5389 tails on Semantic::{variant:?}"
5390 );
5391 let owned_box: Box<str> = <Box<str> as From<super::Semantic>>::from(variant);
5392 assert_eq!(
5393 via_owned_from,
5394 owned_box.as_bytes().to_vec(),
5395 "From<Semantic> for Vec<u8> and From<Semantic> for \
5396 Box<str> must resolve to byte-equal byte-tails on \
5397 Semantic::{variant:?}"
5398 );
5399 let owned_arc: std::sync::Arc<str> =
5400 <std::sync::Arc<str> as From<super::Semantic>>::from(variant);
5401 assert_eq!(
5402 via_owned_from,
5403 owned_arc.as_bytes().to_vec(),
5404 "From<Semantic> for Vec<u8> and From<Semantic> for \
5405 std::sync::Arc<str> must resolve to byte-equal byte-\
5406 tails on Semantic::{variant:?}"
5407 );
5408 let owned_rc_str: std::rc::Rc<str> =
5409 <std::rc::Rc<str> as From<super::Semantic>>::from(variant);
5410 assert_eq!(
5411 via_owned_from,
5412 owned_rc_str.as_bytes().to_vec(),
5413 "From<Semantic> for Vec<u8> and From<Semantic> for \
5414 std::rc::Rc<str> must resolve to byte-equal byte-tails \
5415 on Semantic::{variant:?}"
5416 );
5417 // Reject the `format!("{:?}", variant)` PascalCase byte-
5418 // string any future per-theme render site would otherwise
5419 // reach without the substrate-primitive
5420 // [`super::Semantic::as_str`] accessor: the byte-owned
5421 // reverse-projection axis must not silently collapse back
5422 // onto the derived [`std::fmt::Debug`] output, whose bytes
5423 // differ on every arm (`"Keyword"` vs. `"keyword"`,
5424 // `"KeywordArg"` vs. `"keyword-arg"`). A future
5425 // `#[derive(Debug)]` swap for a hand-rolled `impl Debug` or
5426 // a silent re-route of the byte-owned axis onto the sibling
5427 // `Debug` output trips here rather than at a downstream
5428 // operator's terminal-scroll.
5429 let debug_bytes = format!("{variant:?}").into_bytes();
5430 assert_ne!(
5431 via_owned_from, debug_bytes,
5432 "From<Semantic> for Vec<u8> must land on the canonical-\
5433 lowercase kebab byte-string (Semantic::as_str), not the \
5434 PascalCase byte-string `format!(\"{{:?}}\", variant)`; \
5435 if this fails on Semantic::{variant:?}, the byte-owned \
5436 axis has silently collapsed back onto the Debug-derive \
5437 output"
5438 );
5439 }
5440 // `<T: Into<Vec<u8>>>`-bound-consumer witness on both owned and
5441 // borrowed input shapes: the generic owned-byte-input function
5442 // `generic_owned_bytes_sink` (lifted above per
5443 // `clippy::items_after_statements`) accepts a
5444 // [`super::Semantic`] and a `&Semantic` directly through the
5445 // trait bound, without the caller open-coding the three-hop
5446 // `semantic.as_str().as_bytes().to_vec()` composition.
5447 for &variant in super::Semantic::ALL {
5448 let via_generic_owned = generic_owned_bytes_sink(variant);
5449 // Bind the borrowed-input path through an explicit
5450 // `&Semantic` local so the generic-consumer witness routes
5451 // through `From<&Semantic> for Vec<u8>` (T binds to
5452 // `&Semantic`) rather than clippy-collapsing the borrow
5453 // onto the owned-input `From<Semantic> for Vec<u8>` peer.
5454 let variant_ref: &super::Semantic = &variant;
5455 let via_generic_borrowed = generic_owned_bytes_sink(variant_ref);
5456 let via_method_bytes: Vec<u8> = variant.as_str().as_bytes().to_vec();
5457 assert_eq!(
5458 via_generic_owned, via_method_bytes,
5459 "generic `<T: Into<Vec<u8>>>`-bound consumer on the \
5460 owned-input surface must byte-equal the substrate-\
5461 primitive as_str accessor's byte-tail on \
5462 Semantic::{variant:?}"
5463 );
5464 assert_eq!(
5465 via_generic_borrowed, via_method_bytes,
5466 "generic `<T: Into<Vec<u8>>>`-bound consumer on the \
5467 borrowed-input surface must byte-equal the substrate-\
5468 primitive as_str accessor's byte-tail on \
5469 Semantic::{variant:?}"
5470 );
5471 }
5472 // `std::io::Write::write_all`-shape owned-byte-sink surface
5473 // witness on both owned and borrowed input shapes — the primary
5474 // compounding target on the byte-owned reverse-projection axis
5475 // is a future per-theme audit-log payload composer that binds
5476 // its byte-tag input through exactly this trait bound.
5477 for &variant in super::Semantic::ALL {
5478 let via_method_bytes: Vec<u8> = variant.as_str().as_bytes().to_vec();
5479 let mut sink_owned = MockOwnedByteSink::new();
5480 sink_owned.write_all(variant);
5481 let owned_written = sink_owned.finalize();
5482 assert_eq!(
5483 owned_written, via_method_bytes,
5484 "std::io::Write::write_all-shape owned-byte-sink \
5485 surface on the owned-input surface must byte-equal the \
5486 substrate-primitive as_str accessor's byte-tail on \
5487 Semantic::{variant:?}"
5488 );
5489 let mut sink_borrowed = MockOwnedByteSink::new();
5490 let variant_ref: &super::Semantic = &variant;
5491 sink_borrowed.write_all(variant_ref);
5492 let borrowed_written = sink_borrowed.finalize();
5493 assert_eq!(
5494 borrowed_written, via_method_bytes,
5495 "std::io::Write::write_all-shape owned-byte-sink \
5496 surface on the borrowed-input surface must byte-equal \
5497 the substrate-primitive as_str accessor's byte-tail on \
5498 Semantic::{variant:?}"
5499 );
5500 }
5501 }
5502
5503 #[test]
5504 fn semantic_try_from_bytes_routes_through_from_wire_accessor() {
5505 // Fail-before-pass-after byte-parity pin on the newly lifted
5506 // `impl TryFrom<&[u8]> for Semantic` — asserts the trait-
5507 // idiomatic byte-view reverse-projection standard-library impl
5508 // and the substrate-primitive [`super::Semantic::from_wire`]
5509 // `Option<Self>` accessor resolve to the same sixteen-arm
5510 // canonical-lowercase-kebab semantic-style accept-set across
5511 // every arm the exhaustive [`super::Semantic::ALL`] slice
5512 // enumerates. Extends the substrate-wide trait-idiomatic byte-
5513 // view reverse-projection axis onto the *fifth outside-
5514 // `caixa-core`* closed-set fieldless typed-enum peer (and the
5515 // first inside `caixa-theme`) — matching the paired
5516 // [`super::Semantic`] byte-view forward triple ([`AsRef<[u8]>`],
5517 // [`From<Semantic> for Vec<u8>`],
5518 // [`From<&Semantic> for Vec<u8>`]) and the paired str-view
5519 // reverse-projection axis ([`TryFrom<&str> for Semantic`])
5520 // already walked on this enum, and matching the trajectory the
5521 // first-mover outside-`caixa-core`
5522 // `caixa_arch::invariants::InvariantKind` `TryFrom<&[u8]>` impl
5523 // (40b7417), second-mover outside-`caixa-core`
5524 // `caixa_arch::report::ArchVerdict` `TryFrom<&[u8]>` impl
5525 // (4dbca85), third-mover outside-`caixa-core`
5526 // `caixa_lint::diagnostic::Severity` `TryFrom<&[u8]>` impl
5527 // (f11dc96), and fourth-mover outside-`caixa-core`
5528 // `caixa_lint::diagnostic::FixSafety` `TryFrom<&[u8]>` impl
5529 // (46a3e3e) walked before it.
5530 //
5531 // Rust's standard library carries no blanket
5532 // `impl<T: for<'a> TryFrom<&'a str>> TryFrom<&[u8]> for T`, so
5533 // a two-hop composition through [`std::str::from_utf8`] + the
5534 // paired [`TryFrom<&str>`] axis is reachable through the pre-
5535 // existing str-view reverse-projection axis alone. But that
5536 // two-hop shape has no compile-time link back to the byte-view
5537 // reverse-projection axis, forces every downstream
5538 // `<T: for<'a> TryFrom<&'a [u8]>>`-bound consumer to open-code
5539 // the composition at every call site, and admits a silent
5540 // split whenever a future call site takes a sibling byte-
5541 // projection axis whose parse arm-set carries no compile-time
5542 // byte-view surface. This impl closes the byte-view reverse-
5543 // projection axis at the substrate-primitive
5544 // [`super::Semantic::from_wire`] accessor so every future
5545 // `<T: for<'a> TryFrom<&'a [u8]>>`-bound consumer reaches the
5546 // same sixteen-arm semantic-style accept-set through one trait
5547 // dispatch.
5548 for &variant in super::Semantic::ALL {
5549 let wire_bytes: &[u8] = variant.as_str().as_bytes();
5550 assert_eq!(
5551 <super::Semantic as TryFrom<&[u8]>>::try_from(wire_bytes),
5552 Ok(variant),
5553 "TryFrom<&[u8]> impl on Semantic must round-trip \
5554 Semantic::{variant:?}.as_str().as_bytes() back to \
5555 Ok(Semantic::{variant:?}) — divergence from \
5556 Semantic::from_wire signals a silent detour off the \
5557 substrate-primitive accessor"
5558 );
5559 assert_eq!(
5560 <super::Semantic as TryFrom<&[u8]>>::try_from(wire_bytes).ok(),
5561 super::Semantic::from_wire(variant.as_str()),
5562 "TryFrom<&[u8]> ok()-projection on \
5563 Semantic::{variant:?}.as_str().as_bytes() must byte-\
5564 equal Semantic::from_wire on the paired &str input"
5565 );
5566 // Cross-axis witness: the byte-view reverse-projection
5567 // axis must agree with the paired str-view reverse-
5568 // projection axis ([`TryFrom<&str>`]) on every accepted
5569 // arm — the two reverse paths share one semantic-style
5570 // accept-set through the substrate-primitive `from_wire`
5571 // accessor.
5572 let via_str: Result<super::Semantic, ()> =
5573 <super::Semantic as TryFrom<&str>>::try_from(variant.as_str());
5574 let via_bytes: Result<super::Semantic, ()> =
5575 <super::Semantic as TryFrom<&[u8]>>::try_from(wire_bytes);
5576 assert_eq!(
5577 via_bytes, via_str,
5578 "TryFrom<&[u8]> and TryFrom<&str> reverse-projection \
5579 axes on Semantic must agree on \
5580 Semantic::{variant:?} — divergence signals the byte-\
5581 view and str-view reverse paths have drifted off the \
5582 same substrate-primitive from_wire accessor"
5583 );
5584 // Forward/reverse byte-view cross-axis witness: feed the
5585 // paired [`AsRef<[u8]>`] byte-tail back through the new
5586 // impl and assert it round-trips to the originating arm.
5587 let via_asref: &[u8] = <super::Semantic as AsRef<[u8]>>::as_ref(&variant);
5588 assert_eq!(
5589 <super::Semantic as TryFrom<&[u8]>>::try_from(via_asref),
5590 Ok(variant),
5591 "TryFrom<&[u8]> ∘ AsRef<[u8]> must round-trip \
5592 Semantic::{variant:?} — divergence signals the \
5593 forward and reverse byte-view axes have drifted off \
5594 the same substrate-primitive as_str/from_wire pair"
5595 );
5596 // Byte-owned round-trip witness: feed the paired
5597 // [`From<Semantic> for Vec<u8>`] owned byte-tail back
5598 // through the byte-view reverse impl as a borrowed slice
5599 // and assert the round-trip lands on the originating arm
5600 // — locks the owned and borrowed byte projections
5601 // together at the substrate-primitive accessor.
5602 let owned_bytes: Vec<u8> = <Vec<u8> as From<super::Semantic>>::from(variant);
5603 assert_eq!(
5604 <super::Semantic as TryFrom<&[u8]>>::try_from(owned_bytes.as_slice()),
5605 Ok(variant),
5606 "TryFrom<&[u8]> ∘ From<Semantic> for Vec<u8> must \
5607 round-trip Semantic::{variant:?} — divergence \
5608 signals the byte-owned reverse-projection axis has \
5609 drifted off the paired byte-view reverse axis"
5610 );
5611 // Borrowed-input byte-owned round-trip witness: same
5612 // discipline on the paired [`From<&Semantic> for Vec<u8>`]
5613 // owned byte-tail — closes the four-corner {owned-input,
5614 // borrowed-input} × {owned-output byte-vec, borrowed-
5615 // output byte-slice} projection square through the new
5616 // byte-view reverse impl.
5617 let borrowed_owned_bytes: Vec<u8> = <Vec<u8> as From<&super::Semantic>>::from(&variant);
5618 assert_eq!(
5619 <super::Semantic as TryFrom<&[u8]>>::try_from(borrowed_owned_bytes.as_slice()),
5620 Ok(variant),
5621 "TryFrom<&[u8]> ∘ From<&Semantic> for Vec<u8> must \
5622 round-trip Semantic::{variant:?} — divergence \
5623 signals the borrowed-input byte-owned axis has \
5624 drifted off the paired byte-view reverse axis"
5625 );
5626 }
5627 }
5628
5629 #[test]
5630 fn semantic_try_from_bytes_rejects_unknown_and_non_utf8_bytes() {
5631 // Rejection witness on the `impl TryFrom<&[u8]> for Semantic`
5632 // — sweeps two rejection paths the byte-view reverse-
5633 // projection axis collapses onto the single unit-error
5634 // `Err(())` return: the invalid-UTF-8 rejection path
5635 // ([`std::str::from_utf8`] returns `Err` before
5636 // [`super::Semantic::from_wire`] runs) and the valid-UTF-8-
5637 // but-unknown-wire rejection path
5638 // ([`super::Semantic::from_wire`] returns `None` on a byte-
5639 // string outside the sixteen-arm semantic-style accept-set).
5640 // Both must reject, so a future accidental widening of the
5641 // trait impl's accept-set (a case-fold path, a silent
5642 // inclusion of the pre-lift PascalCase Debug-derived shapes
5643 // like `"Keyword"` / `"KeywordArg"` on the wire axis, a
5644 // silent overlap with sibling closed-set canonical tags on
5645 // other axes, a stray fallback that maps invalid UTF-8 onto
5646 // a default arm rather than the trait-idiomatic
5647 // `Err(())`) trips at caixa-theme test time.
5648 //
5649 // Non-UTF-8 candidates:
5650 // - a lone 0xFF byte (never valid as a UTF-8 leading byte)
5651 // - a lone 0x80 continuation byte with no leading byte
5652 // - a truncated multi-byte sequence (0xC3 without
5653 // continuation)
5654 // - a UTF-16 BOM-style byte pair the UTF-8 validator
5655 // rejects
5656 // - a UTF-16 surrogate half rejected by UTF-8
5657 let non_utf8_rejected: &[&[u8]] = &[
5658 &[0xFF],
5659 &[0x80],
5660 &[0xC3],
5661 &[0xFF, 0xFE],
5662 &[0xED, 0xA0, 0x80],
5663 ];
5664 for &input in non_utf8_rejected {
5665 assert_eq!(
5666 <super::Semantic as TryFrom<&[u8]>>::try_from(input),
5667 Err(()),
5668 "TryFrom<&[u8]> impl on Semantic must reject the \
5669 non-UTF-8 byte-sequence {input:?} with Err(()) — \
5670 silent acceptance signals the UTF-8 validation path \
5671 collapsed onto a default arm rather than the trait-\
5672 idiomatic unit-error"
5673 );
5674 }
5675 // Valid-UTF-8-but-unknown-wire candidates mirror the corpus
5676 // the sibling `semantic_try_from_str_rejects_unknown_byte_strings`
5677 // str-view rejection witness already pins on the paired
5678 // [`TryFrom<&str>`] axis: the empty byte-string, whitespace-
5679 // only padding, PascalCase / uppercase rebrand candidates,
5680 // Levenshtein-neighbor typos, the trajectory-item candidates
5681 // `b"namespace"` / `b"deleted"` the sibling
5682 // [`super::Semantic::ALL`] doc block names, sibling closed-
5683 // set canonical tags on other axes (`b"safe"`, `b"unsafe"`,
5684 // `b"proven"`, `b"rejected"`, `b"biblioteca"`, `b"servico"`,
5685 // `b"one-for-one"`, `b"empty"`, `b"safety"`, `b"compliance"`),
5686 // and trailing/leading-whitespace-padded canonical tags.
5687 let unknown_wire_rejected: &[&[u8]] = &[
5688 b"",
5689 b" ",
5690 b"\n",
5691 b"\t",
5692 b"Keyword",
5693 b"KEYWORD",
5694 b"KeywordArg",
5695 b"keyword_arg",
5696 b"keyword arg",
5697 b"keywordarg",
5698 b"keywords",
5699 b"keywor",
5700 b"namespace",
5701 b"deleted",
5702 b"safe",
5703 b"unsafe",
5704 b"proven",
5705 b"rejected",
5706 b"biblioteca",
5707 b"servico",
5708 b"one-for-one",
5709 b"empty",
5710 b"safety",
5711 b"compliance",
5712 b"keyword ",
5713 b" keyword",
5714 b"keyword\n",
5715 b"keyword\t",
5716 b"?",
5717 b"\"keyword\"",
5718 ];
5719 for &input in unknown_wire_rejected {
5720 assert_eq!(
5721 <super::Semantic as TryFrom<&[u8]>>::try_from(input),
5722 Err(()),
5723 "TryFrom<&[u8]> impl on Semantic must reject the \
5724 valid-UTF-8-but-unknown-wire byte-string {input:?} \
5725 with Err(()) — silent acceptance signals an accept-\
5726 set widening off the paired Semantic::from_wire \
5727 resolver, or a cross-axis leak from a sibling \
5728 closed-set typed-enum axis's non-shared arm-set"
5729 );
5730 }
5731 }
5732}