caixa_core/dialeto.rs
1//! `defcaixa` is spoken by two unrelated declarations. This module makes that
2//! a **typed fact** instead of an anonymous parse failure.
3//!
4//! # The finding
5//!
6//! Measured 2026-07-31 over the pleme-io org checkout (270 `caixa.lisp` /
7//! `*.caixa.lisp` files found with `rg --no-ignore`; a bare `rg` from the org
8//! root returns 0, which is how this stayed invisible), the corpus splits into
9//! two schemas that share zero required slots:
10//!
11//! * [`CaixaDialeto::Pacote`] — this crate's [`crate::Caixa`]. `:nome
12//! :versao :kind :deps :bibliotecas :exe :servicos` + the supervisor/mesh
13//! slots. It declares a **tatara-lisp package**: the thing `feira` resolves,
14//! builds, links and publishes.
15//! * [`CaixaDialeto::Molde`] — `:name :kind :ecosystem :package {…} :workflows
16//! […] :ci-config {…} :files […]`. It declares a **repo's generated
17//! surface**: which foreign ecosystem (rust / go / python / …), that
18//! ecosystem's own package metadata, the CI shims to emit, and byte-captured
19//! file bodies. Read by `pleme-doc-gen`, never by `feira`.
20//!
21//! `:package`, `:ecosystem`, `:supports` and `:profile` have no counterpart in
22//! [`crate::Caixa`] at all — the theory doc's own D4 note records the same
23//! thing: those manifests "are authored against a schema that does not exist in
24//! Rust". They are not two spellings of one declaration. They are two domains
25//! that collided on one word, because *caixa* names a box and both are boxes.
26//!
27//! # Why this is not a bug report about broken files
28//!
29//! The Molde-dialect files are not malformed. They are correct inputs to their
30//! own consumer, and nothing in the shipped `feira` reads them, so nothing is
31//! failing today. The hazard is **latent and certain**: any new declarative
32//! surface written against "a `.caixa.lisp` is a [`crate::Caixa`]" meets a
33//! corpus where that is false for the large majority of files, and gets a flat
34//! unknown-keyword rejection that reads as "this manifest is broken" rather
35//! than "this manifest is not yours".
36//!
37//! # What this module does about it
38//!
39//! [`classify`] is total: every `(defcaixa …)` form lands in exactly one
40//! [`CaixaDialeto`], including [`CaixaDialeto::Desconhecido`] for one that
41//! matches neither. [`crate::Caixa::from_lisp`] runs it first, so a foreign
42//! dialect is [`crate::ManifestError::DialetoEstrangeiro`] — an error that
43//! names the dialect it found and the consumer that speaks it — rather than an
44//! unknown-kwarg error indistinguishable from a typo.
45//!
46//! Tier-honest: this is **parse-time rejection with a named cause**, not
47//! unrepresentability. A caller that ignores the `Err` still gets nothing
48//! useful; what it can no longer do is mistake "wrong dialect" for "bad file".
49
50use tatara_lisp::{Atom, Sexp};
51
52/// Which `(defcaixa …)` declaration a source speaks.
53///
54/// The [`gen_platform::IsVariant`] derive emits per-arm arm-discriminator
55/// predicates (`is_pacote` / `is_molde` / `is_molde_posicional` /
56/// `is_desconhecido`) as substrate-side typed dispatches on the closed
57/// four-arm dialect-classification discriminator. Peer of the sibling
58/// closed-set fieldless typed enums' [`crate::CaixaKind`] /
59/// [`crate::supervisor::RestartStrategy`] /
60/// [`crate::supervisor::RestartPolicy`] /
61/// [`crate::aplicacao::PlacementStrategy`] /
62/// [`crate::aplicacao::RateLimitUnit`] /
63/// [`crate::dep::DepList`] `IsVariant` derives on the sibling
64/// closed-set typed-enum discriminator axes.
65///
66/// The pre-lift `is_molde_family` predicate hand-rolled its own
67/// `matches!(self, Self::Molde | Self::MoldePosicional)` two-arm literal
68/// with no compile-time link back to the closed set — post-lift it routes
69/// through `self.is_molde() || self.is_molde_posicional()` so a future
70/// arm rename (e.g. `Molde → MoldeKW` under an M4 vocabulary shift) trips
71/// exhaustively at every derive-generated predicate site rather than
72/// leaving the hand-rolled `matches!` silently drifting.
73#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, gen_platform::IsVariant)]
74pub enum CaixaDialeto {
75 /// This crate's [`crate::Caixa`] — a tatara-lisp package manifest.
76 /// Keyword-argument form headed by `:nome`.
77 Pacote,
78 /// `pleme-doc-gen`'s repo-surface declaration, keyword-argument form
79 /// headed by `:name` (plus `:ecosystem` / `:package`).
80 Molde,
81 /// The same declaration as [`Self::Molde`], written with the package name
82 /// as a bare positional symbol — `(defcaixa todoku-go :kind :Biblioteca
83 /// :ecosystem :go …)`. `pleme-doc-gen`'s parser reads the first token
84 /// after the head as the name, so this is one arity of one declaration,
85 /// not a third schema.
86 MoldePosicional,
87 /// A `(defcaixa …)` form matching neither. Kept as a variant rather than
88 /// an error so [`classify`] is total and a census can COUNT the residue —
89 /// a classifier that threw here would report "0 unknown" by construction.
90 Desconhecido,
91}
92
93impl CaixaDialeto {
94 /// Exhaustive iteration surface for every consumer that walks the
95 /// closed four-arm [`CaixaDialeto`] discriminator set — the
96 /// [`feira dialeto`](../../caixa_feira/cmd/dialeto/index.html)
97 /// census counter's per-arm accept-set, a future
98 /// `feira dialeto --list-dialects` CLI listing of the accepted
99 /// classifications, a future M4 `mesh.pleme.io/v1alpha1/Manifesto`
100 /// CR materializer's admission-webhook rejection body naming the
101 /// accepted-dialect set, any future census-report shape probe that
102 /// sweeps every arm to compute per-arm coverage. A future arm
103 /// addition (a fifth dialect the [`crate::dialeto`] module doc's
104 /// "third dialect" hazard actualises — the module explicitly frames
105 /// its purpose as "what stops a third dialect appearing", and this
106 /// slice is the substrate-side answer: the arm-set is one edit and
107 /// every consumer picks up the new entry by construction) extends
108 /// this slice as one edit and every downstream consumer picks up
109 /// the new entry through the shared iteration; the compiler-checked
110 /// exhaustiveness on the sibling method `match` arms
111 /// ([`Self::palavra_canonica`] / [`Self::consumidor`] /
112 /// [`Self::descricao`] / [`std::fmt::Display`]) is the build-time
113 /// guarantee that no arm forgets to grow.
114 ///
115 /// Peer of the sibling closed-set typed enums'
116 /// [`crate::CaixaKind::ALL`] (6b1f4fb) /
117 /// [`crate::aplicacao::PlacementStrategy::ALL`] (18c7342) /
118 /// [`crate::aplicacao::RateLimitUnit::ALL`] (6bce03d) /
119 /// [`crate::dep::DepList::ALL`] (45ee563) /
120 /// [`crate::supervisor::RestartStrategy::ALL`] (4eec29c) /
121 /// [`crate::supervisor::RestartPolicy::ALL`] (dd32ccf)
122 /// exhaustive-iteration surfaces — the seventh closed-set typed
123 /// enum on the caixa surface to converge onto the same
124 /// one-canonical-arm-list-per-enum discipline, and the first
125 /// dialect-classification axis (as distinct from an OTP-shape M2
126 /// slot or an M3 mesh slot) to reach it. Order matches variant
127 /// declaration order verbatim (`Pacote` → `Molde` →
128 /// `MoldePosicional` → `Desconhecido`) so the slice is the
129 /// canonical ordering every listing / rendering consumer defers to.
130 pub const ALL: &'static [Self] = &[
131 Self::Pacote,
132 Self::Molde,
133 Self::MoldePosicional,
134 Self::Desconhecido,
135 ];
136
137 /// Substrate-canonical `PascalCase` variant-name byte-string every consumer
138 /// that formats the dialect as census-facing text lands on. Returns the
139 /// per-arm `PascalCase` name of the variant (`"Pacote"` / `"Molde"` /
140 /// `"MoldePosicional"` / `"Desconhecido"`) — the one canonical
141 /// byte-string the paired [`std::fmt::Display`] impl routes through so
142 /// every downstream consumer (the `feira dialeto` census counter output
143 /// line, a future `feira dialeto --list-dialects` CLI enumeration, a
144 /// future M4 `mesh.pleme.io/v1alpha1/Manifesto` CR materializer's
145 /// admission-webhook rejection body naming the accepted-dialect set)
146 /// reaches for the same substrate primitive rather than the pre-lift
147 /// hand-rolled four-arm literal-string match every [`std::fmt::Display`]
148 /// call previously routed through in place.
149 ///
150 /// Peer of the sibling closed-set typed enums'
151 /// [`crate::CaixaKind::as_str`] / [`crate::supervisor::RestartStrategy::as_str`]
152 /// / [`crate::supervisor::RestartPolicy::as_str`] /
153 /// [`crate::aplicacao::PlacementStrategy::as_str`] /
154 /// [`crate::dep::DepList::as_str`] projections on the sibling closed-set
155 /// typed-enum discriminator axes — the seventh (and last unlifted)
156 /// closed-set fieldless typed enum on the caixa surface to converge
157 /// onto the same one-canonical-byte-string-per-arm-through-`as_str`
158 /// discipline the six siblings already carry. Unlike [`crate::CaixaKind`]
159 /// (which carries two axes: `as_str` returning lowercase Portuguese
160 /// diagnostic form vs `wire_name` returning `PascalCase` tatara-lisp
161 /// author-surface bytes), [`CaixaDialeto`] is an internal
162 /// classification with no wire surface — the `PascalCase` variant name
163 /// is the census-facing form every consumer reads, so `as_str`
164 /// suffices without a paired `wire_name` axis.
165 #[must_use]
166 pub const fn as_str(self) -> &'static str {
167 match self {
168 Self::Pacote => "Pacote",
169 Self::Molde => "Molde",
170 Self::MoldePosicional => "MoldePosicional",
171 Self::Desconhecido => "Desconhecido",
172 }
173 }
174
175 /// Substrate-canonical reverse projection on the [`CaixaDialeto`]
176 /// closed-set dialect-classification axis — parses the `PascalCase`
177 /// variant-name byte-string back to the typed variant, or `None` when
178 /// `s` is outside the closed-set arm-string set [`Self::as_str`]
179 /// emits. Walks the same four `"Pacote"` / `"Molde"` /
180 /// `"MoldePosicional"` / `"Desconhecido"` byte-strings the sibling
181 /// [`Self::as_str`] emitter returns, so the parse and emit halves of
182 /// the round-trip migrate through one caixa-core edit on any future
183 /// arm addition (the module doc's "third dialect" hazard actualising
184 /// as a fifth arm) — the compiler-checked exhaustiveness on
185 /// [`Self::as_str`]'s `match self` arms and the round-trip pin
186 /// [`tests::caixa_dialeto_round_trips_through_as_str_and_from_wire`]
187 /// together lock the two halves mutually.
188 ///
189 /// Prior to this lift the substrate carried only the forward
190 /// `Self → &str` projection on the dialect-classification axis (the
191 /// [`Self::as_str`] emitter, the [`std::fmt::Display`] impl routed
192 /// through it, the [`AsRef<str>`] impl routed through it) — every
193 /// future consumer that wanted to promote the census-facing text back
194 /// to the typed enum (a future `feira dialeto --filter
195 /// <Pacote|Molde|MoldePosicional|Desconhecido>` CLI arg-parse that
196 /// binds the wire form into the typed enum before dispatching to the
197 /// per-arm counter, a future M4 `mesh.pleme.io/v1alpha1/Manifesto`
198 /// CR materializer's admission-time re-parse of the per-dialect
199 /// audit body, a future audit-report re-loader that binds a prior
200 /// [`Self::as_str`] output back to the typed enum for cross-run
201 /// comparison) would have had to re-inline a four-arm `match s`
202 /// cascade that expressed no compile-time link back to the typed
203 /// [`CaixaDialeto`] enum.
204 ///
205 /// Same closed-set-reverse-projection discipline the sibling
206 /// [`crate::CaixaKind::from_wire`] (2aa6d23) /
207 /// [`crate::supervisor::RestartStrategy::from_wire`] (4eec29c) /
208 /// [`crate::supervisor::RestartPolicy::from_wire`] (dd32ccf) /
209 /// [`crate::aplicacao::PlacementStrategy::from_wire`] (18c7342) /
210 /// [`crate::dep::DepList::from_wire`] (45ee563) typed enums carry on
211 /// the peer wire-side `str → Self` axes — extends the family onto
212 /// the seventh closed-set fieldless typed enum on the caixa surface
213 /// (the dialect-classification axis), matching the same
214 /// two-way `str ↔ Self` round-trip every sibling closed-set enum
215 /// already carries. Method-named `from_wire` (not `from_str`) to
216 /// match the peer shapes verbatim and side-step the derived
217 /// [`std::str::FromStr`] impls the sibling
218 /// [`gen_platform::FromStrKind`]-carrying axes install on their
219 /// kebab-case dispatcher-catalog identity. Returns `Option<Self>`
220 /// (rather than `Result<Self, _>`) to match the peer shapes: the
221 /// caller picks the diagnostic form appropriate for its use site.
222 #[must_use]
223 pub fn from_wire(s: &str) -> Option<Self> {
224 match s {
225 "Pacote" => Some(Self::Pacote),
226 "Molde" => Some(Self::Molde),
227 "MoldePosicional" => Some(Self::MoldePosicional),
228 "Desconhecido" => Some(Self::Desconhecido),
229 _ => None,
230 }
231 }
232
233 /// The keyword an author should write for this dialect, once the
234 /// migration named in [`Self::consumidor`] completes.
235 #[must_use]
236 pub const fn palavra_canonica(self) -> &'static str {
237 match self {
238 Self::Pacote => "defcaixa",
239 Self::Molde | Self::MoldePosicional => "defmolde",
240 Self::Desconhecido => "?",
241 }
242 }
243
244 /// Who reads this dialect.
245 #[must_use]
246 pub const fn consumidor(self) -> &'static str {
247 match self {
248 Self::Pacote => "caixa-core / feira",
249 Self::Molde | Self::MoldePosicional => "pleme-doc-gen",
250 Self::Desconhecido => "nobody known",
251 }
252 }
253
254 /// A one-line description for a census row or an error message.
255 #[must_use]
256 pub const fn descricao(self) -> &'static str {
257 match self {
258 Self::Pacote => "tatara-lisp package manifest (:nome :versao :kind :deps …)",
259 Self::Molde => "repo-surface declaration (:name :ecosystem :package {…} …)",
260 Self::MoldePosicional => {
261 "repo-surface declaration, positional name (defcaixa <nome> :kind …)"
262 }
263 Self::Desconhecido => "unrecognised — matches no known defcaixa schema",
264 }
265 }
266
267 /// True when this arm belongs to the `defmolde` declaration family —
268 /// the two-arity closure of [`Self::Molde`] and [`Self::MoldePosicional`]
269 /// under the shared `defmolde` head keyword the sibling
270 /// [`Self::palavra_canonica`] projection already collapses onto
271 /// `"defmolde"` for both arms (and the sibling [`Self::consumidor`]
272 /// projection collapses onto `"pleme-doc-gen"` for the same two arms).
273 /// False on [`Self::Pacote`] (the sibling `defcaixa` tatara-lisp
274 /// package manifest, [`Self::palavra_canonica`] `→ "defcaixa"`) and
275 /// on [`Self::Desconhecido`] (the residue that names no known
276 /// declaration, [`Self::palavra_canonica`] `→ "?"`).
277 ///
278 /// The [`Self::Molde`] / [`Self::MoldePosicional`] split is one
279 /// declaration written two ways ([`Self::MoldePosicional`]'s
280 /// variant-declaration docstring at [`Self::MoldePosicional`] frames
281 /// it exactly: "the same declaration as [`Self::Molde`], written with
282 /// the package name as a bare positional symbol … this is one arity
283 /// of one declaration, not a third schema"). Every downstream gate
284 /// that keys off "does this dialect belong to the `defmolde` family"
285 /// (as distinct from the four-arm-per-arm census-counter axis the
286 /// sibling `feira dialeto` verb already fans on separately at
287 /// `caixa-feira/src/cmd/dialeto.rs:110-127`) previously hand-rolled
288 /// the two-arm collapse inline as `matches!(d, CaixaDialeto::Molde |
289 /// CaixaDialeto::MoldePosicional)` — a compile-time-anonymous
290 /// two-arm literal set with no link back to the [`CaixaDialeto`]
291 /// variant declaration nor to the sibling
292 /// [`Self::palavra_canonica`] / [`Self::consumidor`] projections
293 /// that already carry the same two-arm collapse under the shared
294 /// `defmolde` / `pleme-doc-gen` axis. The `feira dialeto` verb's
295 /// [`caixa-feira/src/cmd/dialeto.rs`] carried the same
296 /// `matches!` twice — once in the `--strict-palavra` gate that
297 /// refuses a repo-surface declaration still written as
298 /// `(defcaixa …)`, once in the wrong-declaration-under-`caixa.lisp`
299 /// gate that refuses a repo-surface declaration under the filename
300 /// `feira` loads as a package manifest — with no compile-time link
301 /// between the two hand-rolled arm sets. A future arm addition (the
302 /// module doc's "third dialect" hazard actualises as a fifth arm
303 /// [`CaixaDialeto`] that belongs to the `defmolde` declaration
304 /// family — a third arity variant, an alias-declaration family
305 /// pleme-doc-gen sharpens as its schema evolves) would silently
306 /// split the two hand-rolled `matches!` arm-sets from each other
307 /// and from the paired [`Self::palavra_canonica`] projection: one
308 /// call site picks up the new arm, one does not, and the disagreement
309 /// surfaces far from the arm-addition commit as a `feira dialeto`
310 /// consumer reporting a repo-surface declaration under one gate but
311 /// not the other. Routing every "belongs to the `defmolde` family"
312 /// predicate through this one substrate primitive closes the axis:
313 /// a future arm addition lands one match arm here (a compile-time
314 /// exhaustiveness error otherwise), not a coordinated per-`matches!`
315 /// rewrite across every caller.
316 ///
317 /// Peer of the sibling [`crate::CaixaKind::requires_lib`] (0421c22)
318 /// per-arm-set predicate on the [`crate::CaixaKind`] closed-set
319 /// discriminator's "kind requires a `lib/` surface" axis — extends
320 /// the same "one canonical typed predicate per per-arm-set gate,
321 /// one dispatch on the substrate primitive" discipline onto the
322 /// [`CaixaDialeto`] closed-set discriminator's "belongs to the
323 /// `defmolde` declaration family" axis. The dialect-classification
324 /// axis's second per-arm-set predicate (first being the implicit
325 /// palavra_canonica-through-consumidor-through-descricao arm-set
326 /// collapse already carried on the sibling projections) — the first
327 /// explicitly-typed per-arm-set predicate on the axis, matching the
328 /// discipline the sibling M2 [`crate::CaixaKind`] closed-set
329 /// discriminator already carries with `requires_lib`.
330 ///
331 /// Three consumers now route through this one typed dispatch: the
332 /// [`caixa-feira`](../../caixa_feira/cmd/dialeto/index.html) verb's
333 /// `--strict-palavra` gate (refusing a repo-surface declaration
334 /// still written as `(defcaixa …)`), the same verb's wrong-
335 /// declaration-under-`caixa.lisp` gate (refusing a repo-surface
336 /// declaration under the filename `feira` loads as a package
337 /// manifest), and [`crate::Caixa::from_lisp`]'s foreign-dialect
338 /// gate (raising [`crate::ManifestError::DialetoEstrangeiro`] before
339 /// the derive's `parse_kwargs_strict` walk on any `defmolde`-family
340 /// classification — the pre-lift hand-rolled three-arm
341 /// `match { Pacote => {}, Desconhecido => {}, foreign => Err(…) }`
342 /// literal whose `foreign =>` wildcard silently absorbed anything
343 /// non-Pacote-non-Desconhecido, now the third external consumer of
344 /// the `defmolde`-family partition).
345 #[must_use]
346 pub const fn is_molde_family(self) -> bool {
347 // Routed through the derive-generated per-arm predicates
348 // [`Self::is_molde`] + [`Self::is_molde_posicional`] so the
349 // two-arm collapse links compile-time back to the closed-set
350 // typed dispatch every peer arm-set predicate on the caixa
351 // surface (e.g. [`crate::CaixaKind::requires_lib`] on the
352 // sibling `:kind` axis) now carries. Byte-equivalent to the
353 // pre-lift `matches!(self, Self::Molde | Self::MoldePosicional)`
354 // form (the derived `is_*` predicates each expand to the same
355 // `matches!(self, Self::X)` shape by construction), but a
356 // future arm rename or IsVariant `#[is_variant(name = "…")]`
357 // override lands at exactly one dispatch on the substrate
358 // primitive rather than a hand-rolled two-arm literal.
359 self.is_molde() || self.is_molde_posicional()
360 }
361}
362
363/// [`std::fmt::Display`] routed through [`CaixaDialeto::as_str`], so the
364/// pretty-printed byte-string every consumer that formats the dialect as
365/// user-facing / census text lands on (the `feira dialeto` per-manifest
366/// `--list` row, the `feira dialeto` census summary line's per-arm
367/// counters, a future M4 admission-webhook's rejection body naming the
368/// accepted-dialect set) reaches for the same `PascalCase` per-arm
369/// byte-string the [`CaixaDialeto::as_str`] helper returns.
370///
371/// Prior to this lift the [`std::fmt::Display`] impl hand-rolled its own
372/// four-arm literal-string match — the one hand-rolled per-arm dispatch
373/// on the closed [`CaixaDialeto`] discriminator that had NO substrate
374/// primitive accessor to defer to (the sibling [`CaixaDialeto::palavra_canonica`] /
375/// [`CaixaDialeto::consumidor`] / [`CaixaDialeto::descricao`] projections
376/// carry distinct byte-shapes per axis, so none of them could serve as
377/// the Display source). A future variant addition (a fifth dialect the
378/// module doc's "third dialect" hazard actualises) would land one arm at
379/// the enum and per-arm returns at the paired accessors, but a hand-rolled
380/// [`std::fmt::Display`] match would silently drop the new arm to compile-
381/// fail-at-the-match-arm-site rather than through the shared substrate
382/// primitive. Routing [`std::fmt::Display`] through [`CaixaDialeto::as_str`]
383/// closes the last unlifted per-arm `PascalCase`-name projection on the
384/// caixa surface — the seventh (and last unlifted) closed-set fieldless
385/// typed enum on the caixa surface to converge onto the same
386/// `Display`-through-`as_str` discipline the six siblings
387/// ([`crate::CaixaKind`] / [`crate::supervisor::RestartStrategy`] /
388/// [`crate::supervisor::RestartPolicy`] /
389/// [`crate::aplicacao::PlacementStrategy`] / [`crate::aplicacao::RateLimitUnit`]
390/// / [`crate::dep::DepList`]) already carry.
391impl std::fmt::Display for CaixaDialeto {
392 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
393 f.write_str(self.as_str())
394 }
395}
396
397/// Substrate-canonical [`AsRef<str>`] projection on the [`CaixaDialeto`]
398/// closed-set fieldless typed dialect-classification enum — routes through
399/// the same [`CaixaDialeto::as_str`] `pub const fn` scalar accessor the
400/// paired [`std::fmt::Display`] impl already delegates through, so any
401/// future consumer that binds a [`CaixaDialeto`] through the standard-
402/// library `impl AsRef<str>` bound (a [`std::process::Command::arg`]
403/// shell-out that composes the canonical `PascalCase` variant-name into a
404/// `feira dialeto --strict-palavra <Pacote|Molde|MoldePosicional|Desconhecido>`
405/// diagnostic overlay, a `tracing::field::Value::Str`-arm structured-log
406/// recorder on the [`crate::Caixa::from_lisp`] foreign-dialect
407/// [`crate::ManifestError::DialetoEstrangeiro`] refusal path, a
408/// [`std::collections::HashMap`] lookup keyed on the canonical name
409/// through `map.get::<str>(dialeto.as_ref())` on a future M4 admission-
410/// webhook's per-dialect rejection-body composition table) reaches the
411/// paired `"Pacote"` / `"Molde"` / `"MoldePosicional"` / `"Desconhecido"`
412/// byte-string through one substrate-primitive dispatch rather than an
413/// open-coded `.as_str()` re-inlining at every wire-up.
414///
415/// Same "route the trait impl through the substrate-primitive accessor"
416/// discipline the sibling [`crate::CaixaVersion`] [`AsRef<str>`] impl
417/// (16d5c7e), the paired M2 [`crate::supervisor::RestartStrategy`]
418/// [`AsRef<str>`] impl (63eb1a4), the paired M2
419/// [`crate::supervisor::RestartPolicy`] [`AsRef<str>`] impl (419ea81),
420/// the M3 [`crate::aplicacao::PlacementStrategy`] [`AsRef<str>`] impl
421/// (d86edd2), the M3 [`crate::aplicacao::RateLimitUnit`] [`AsRef<str>`]
422/// impl (d8136db), and the top-level [`crate::CaixaKind`] [`AsRef<str>`]
423/// impl (cd2091f) carry — extends the substrate primitive's
424/// [`AsRef<str>`] projection axis onto the seventh closed-set typed enum
425/// on the caixa surface: the dialect-classification axis previously
426/// carried [`fmt::Display`]-through-`as_str` but not yet the paired
427/// [`AsRef<str>`] impl, so a downstream consumer that bound the enum
428/// through the standard-library `AsRef<str>` trait had to reach the
429/// canonical byte-string through an open-coded `.as_str()` call rather
430/// than the trait-idiomatic `.as_ref()` the peer closed-set typed enums
431/// already admit.
432///
433/// Pinned load-bearing by
434/// [`tests::caixa_dialeto_as_ref_str_routes_through_as_str_accessor`]
435/// (byte-parity pin against [`CaixaDialeto::as_str`] across the four-arm
436/// closed set) and
437/// [`tests::caixa_dialeto_as_ref_str_routes_through_display_via_shared_accessor`]
438/// (three-path convergence: `AsRef<str>` + `Display` + `as_str` all
439/// resolve to the same byte-string per arm) — any future silent detour
440/// that routes the impl through a divergent projection (a per-arm inline
441/// `match self { CaixaDialeto::Pacote => "Pacote", … }` re-inlining that
442/// opens a compile-time link to the un-lifted arm-literal, a swap onto
443/// the second-axis [`CaixaDialeto::palavra_canonica`] /
444/// [`CaixaDialeto::consumidor`] / [`CaixaDialeto::descricao`] accessors
445/// that carry distinct byte-shapes per axis) trips at caixa-core test
446/// time under `assert_eq!` rather than at a downstream
447/// `impl AsRef<str>`-bound consumer's silent split.
448impl AsRef<str> for CaixaDialeto {
449 fn as_ref(&self) -> &str {
450 self.as_str()
451 }
452}
453
454/// Trait-idiomatic reverse projection on the [`CaixaDialeto`] closed-set
455/// dialect-classification typed enum — routes byte-for-byte through the
456/// paired substrate-primitive [`CaixaDialeto::from_wire`] `Option<Self>`
457/// accessor so every future consumer that binds a `PascalCase` variant-
458/// name byte-string through the standard-library `.try_into()` /
459/// [`TryFrom`] axis (a future `feira dialeto --filter
460/// <Pacote|Molde|MoldePosicional|Desconhecido>` CLI arg-parse that
461/// composes into `let d: CaixaDialeto = s.try_into()?`, a future audit-
462/// report re-loader binding a prior [`CaixaDialeto::as_str`] output
463/// through `CaixaDialeto::try_from(&s)?`, a generic
464/// `<T: TryFrom<&str>>`-bound loader over any of the substrate's closed-
465/// set typed enums) reaches the same four-arm accept-set the sibling
466/// [`CaixaDialeto::from_wire`] parses through and the sibling
467/// [`CaixaDialeto::as_str`] emits, rather than an open-coded per-arm
468/// `match s { "Pacote" => …, … }` cascade whose arm-set has no
469/// compile-time link back to the substrate primitive.
470///
471/// Complements the pre-existing forward-projection triple
472/// ([`std::fmt::Display`], [`AsRef<str>`], [`CaixaDialeto::as_str`]) with
473/// the paired trait-idiomatic reverse-projection axis: Rust-side
474/// newtype/typed-enum convention pairs [`AsRef<str>`] with either
475/// [`std::str::FromStr`] or [`TryFrom<&str>`] on the same primitive so a
476/// caller who can project *out to* a `&str` can also project *in from*
477/// one. The [`TryFrom<&str>`] axis is deliberately chosen over
478/// [`std::str::FromStr`] to sidestep the `clippy::should_implement_trait`
479/// lint that the sibling method-named `from_wire` would trigger under a
480/// `FromStr` impl (the same design tradeoff the peer
481/// [`crate::CaixaKind`] `TryFrom<&str>` impl (3c83606) and the peer
482/// [`crate::provedor::ferrite::FerriteRuntime::from_wire`] block note)
483/// — this impl closes the trait-idiomatic reverse axis without disturbing
484/// the method-named `from_wire` shape every sibling closed-set typed
485/// enum on the substrate already carries.
486///
487/// `type Error = ()` matches the sibling [`CaixaDialeto::from_wire`]'s
488/// `Option<Self>` return-shape's deliberate deferral of error typing:
489/// the caller picks the diagnostic form appropriate for its use site
490/// (a future `feira dialeto --filter` arg-parse composes its own per-verb
491/// "unknown dialect: <arg> — accepted: {…}" message enumerating
492/// [`CaixaDialeto::ALL`], a future admission-webhook rejection body
493/// wraps the `Err(())` outcome with the accepted-set enumeration for
494/// operator diagnostics, a `Result::map_err` at the call site lifts the
495/// unit-error to a per-verb error type). Same shape the peer
496/// [`crate::CaixaKind`] `TryFrom<&str>` impl (3c83606) and the peer
497/// [`FerriteRuntime::from_wire`] doc block motivate on the sibling
498/// closed-set typed enums' reverse projections.
499///
500/// The paired [`TryFrom<&str>`] impl reaches the same four-arm accept-
501/// set the [`CaixaDialeto::from_wire`] resolver dispatches through, so
502/// any future arm addition (the module doc's "third dialect" hazard
503/// actualises as a fifth arm belonging to the `defmolde` family or a
504/// wholly new declaration) grows the trait-idiomatic axis by
505/// construction — one caixa-core edit on [`CaixaDialeto::from_wire`]
506/// extends both the method-named reverse projection every existing
507/// consumer keys off and the trait-idiomatic reverse projection this
508/// impl exposes, without a coordinated rewrite across every future
509/// `TryFrom<&str>`-bound consumer's arm-set.
510///
511/// Pinned load-bearing by
512/// [`tests::caixa_dialeto_try_from_str_routes_through_from_wire_accessor`]
513/// (byte-parity pin against [`CaixaDialeto::from_wire`] across the four-
514/// arm accept-set) and
515/// [`tests::caixa_dialeto_try_from_str_rejects_unknown_byte_strings`]
516/// (rejection witness against silent accept-set widening).
517impl TryFrom<&str> for CaixaDialeto {
518 type Error = ();
519
520 fn try_from(s: &str) -> Result<Self, Self::Error> {
521 Self::from_wire(s).ok_or(())
522 }
523}
524
525/// Trait-idiomatic forward projection on the [`CaixaDialeto`] closed-set
526/// dialect-classification typed enum — routes byte-for-byte through the
527/// sibling substrate-primitive [`CaixaDialeto::as_str`] `pub const fn`
528/// accessor so every future consumer that needs `&'static str` lifetime
529/// bytes on the dialect-classification axis (a
530/// `tracing::field::valuable::Value::Str` recording where the `Str` arm's
531/// typing demands `&'static str`, a
532/// `Cow::Borrowed::<'static, str>(dialeto.into())` composer on the future
533/// M4 admission-webhook rejection body where the `Cow<'static, str>`
534/// typing rules out the sibling [`AsRef<str>`] borrowed return, a generic
535/// `<T: Into<&'static str>>`-bound serializer or error formatter that
536/// requires the `'static` bound) reaches the same four `"Pacote"` /
537/// `"Molde"` / `"MoldePosicional"` / `"Desconhecido"` byte-strings the
538/// sibling [`CaixaDialeto::as_str`] emitter returns, rather than an
539/// open-coded per-arm literal cascade whose arm-set has no compile-time
540/// link back to the substrate primitive.
541///
542/// Return type is `&'static str` by construction — every
543/// [`CaixaDialeto::as_str`] arm resolves to a compile-time `pub const fn`
544/// return of a `&'static str` literal, so the trait's return-type promise
545/// is upheld structurally without a `String::leak()` cast or a per-arm
546/// inline literal.
547///
548/// Complements the pre-existing reverse-projection axis pair
549/// ([`TryFrom<&str>`] above + method-named [`CaixaDialeto::from_wire`])
550/// with the trait-idiomatic forward-projection axis: Rust-side
551/// newtype/typed-enum convention pairs [`TryFrom<&str>`] with the mirror-
552/// image [`From<Self> for &'static str`] on the same primitive so a
553/// caller who can project *in from* a `&str` can also project *out to*
554/// one under a `'static`-lifetime bound. The
555/// [`AsRef<str>`] impl already carries the same emit-set on the borrowed
556/// return path; this impl closes the trait-idiomatic axis pair with the
557/// stricter `&'static str` lifetime the sibling `AsRef<str>` cannot
558/// promise (its return borrows from `&self`, not from the
559/// [`CaixaDialeto::as_str`] `pub const fn`'s static-string result).
560///
561/// Same "route the trait impl through the substrate-primitive accessor"
562/// discipline the sibling [`crate::supervisor::RestartStrategy`]
563/// `From<Self> for &'static str` impl (523157d — first-mover on this
564/// forward-projection family), [`crate::supervisor::RestartPolicy`]
565/// `From<Self> for &'static str` impl (9fb37d0 — second peer, closing
566/// the M2 OTP-shape sibling pair), and [`crate::CaixaKind`]
567/// `From<Self> for &'static str` impl (edb827b — third peer, opening
568/// the campaign onto the top-level caixa surface) carry — extends the
569/// substrate primitive's trait-idiomatic forward-projection axis onto
570/// the fourth closed-set fieldless typed enum on the caixa surface: the
571/// dialect-classification axis, previously carrying the paired
572/// [`std::fmt::Display`] / [`AsRef<str>`] / [`CaixaDialeto::as_str`] /
573/// [`TryFrom<&str>`] / [`CaixaDialeto::from_wire`] forward+reverse
574/// projections but not yet the trait-idiomatic forward projection with
575/// the `&'static str` lifetime bound.
576///
577/// Unlike the peer [`crate::CaixaKind`] impl (which carries a two-axis
578/// split between the lowercase Portuguese `as_str` diagnostic axis and
579/// the `PascalCase` `wire_name` author-surface axis, so the trait's
580/// round-trip witness must cross through the wire axis rather than
581/// composing the two trait impls directly), [`CaixaDialeto`] is an
582/// internal classification whose [`CaixaDialeto::as_str`] output and
583/// [`CaixaDialeto::from_wire`] input share the same `PascalCase`
584/// vocabulary by construction — the trait-idiomatic axis pair
585/// ([`From<Self> for &'static str`] + [`TryFrom<&str> for Self`])
586/// therefore round-trips directly, without an intermediate wire-vocab
587/// hop.
588///
589/// The paired [`CaixaDialeto::as_str`] accessor's four-arm emit-set is
590/// the single source of truth — every future arm addition (the module
591/// doc's "third dialect" hazard actualises as a fifth arm belonging to
592/// the `defmolde` family or a wholly new declaration) grows the trait-
593/// idiomatic forward axis by construction: one caixa-core edit on
594/// [`CaixaDialeto::as_str`] extends every one of the sibling forward-
595/// projection paths ([`std::fmt::Display`], [`AsRef<str>`],
596/// [`CaixaDialeto::as_str`] itself, and this
597/// [`From<Self> for &'static str`]) without a coordinated rewrite across
598/// every future `Into<&'static str>`-bound consumer's arm-set. This lift
599/// closes the fourth peer on the trait-idiomatic forward-projection
600/// campaign the recently-landed peer commits opened; the remaining ten
601/// closed-set typed enums on the caixa substrate surface
602/// (`PlacementStrategy`, `WitShape`, `RateLimitUnit`,
603/// `PathShapeViolation`, `InvariantKind`, `ArchVerdict`, `Severity`,
604/// `FixSafety`, `Semantic`, `FerriteRuntime`) are the future targets
605/// of this campaign.
606///
607/// Pinned load-bearing by
608/// [`tests::caixa_dialeto_from_into_static_str_routes_through_as_str_accessor`]
609/// (byte-parity pin against [`CaixaDialeto::as_str`] across the four-arm
610/// emit-set, plus a `const`-context materialization witness for the
611/// `&'static str` lifetime promise, plus a paired `.into()` shape
612/// assertion covering the blanket-derived `Into<&'static str>` shape)
613/// and
614/// [`tests::caixa_dialeto_from_into_static_str_and_as_str_partition_the_emit_set`]
615/// (partition pin asserting `<&'static str as From<CaixaDialeto>>::from`
616/// and [`CaixaDialeto::as_str`] agree on every arm, plus a two-way
617/// direct round-trip witness through the paired trait-idiomatic
618/// [`TryFrom<&str>`] axis that closes the two-way `Self ↔ &'static str`
619/// round-trip on the trait-idiomatic axis pair without the wire-vocab
620/// intermediate the peer [`crate::CaixaKind`] axis pair requires).
621impl From<CaixaDialeto> for &'static str {
622 fn from(dialeto: CaixaDialeto) -> &'static str {
623 dialeto.as_str()
624 }
625}
626
627/// Trait-idiomatic *forward* projection on [`CaixaDialeto`] from a
628/// *borrowed* input onto the `&'static str` axis — the borrowed-input
629/// companion to the paired owned-input [`From<CaixaDialeto> for &'static
630/// str`] impl immediately above. Routes byte-for-byte through the same
631/// substrate-primitive [`CaixaDialeto::as_str`] `pub const fn` accessor so
632/// every consumer that binds a `&CaixaDialeto` through the standard-
633/// library `.into()` / [`From<&Self> for &'static str`] axis (a
634/// `CaixaDialeto::ALL.iter().map(<&'static str>::from).collect::<Vec<_>>()`
635/// per-arm accept-set materializer — whose iterator over
636/// `&'static [CaixaDialeto]` yields `&CaixaDialeto`, not `CaixaDialeto`,
637/// so the owned-input [`From<CaixaDialeto>`] axis alone forces every call
638/// site through an explicit `.copied()` / dereference / [`Copy`]-bound
639/// restatement rather than the direct trait-idiomatic projection; a
640/// future generic `<T: Copy + for<'a> Into<&'static str>>`-bound
641/// diagnostic column that walks the `iter().map(Into::into)` shape
642/// verbatim over any of the substrate's closed-set typed enums; the
643/// future M4 admission-webhook rejection body composer's per-dialect
644/// accepted-set enumeration built from an iterated
645/// `CaixaDialeto::ALL.iter().map(|d| d.into())` pipe rather than a
646/// per-arm `match d { … }` cascade; a
647/// `HashMap::<&'static str, CaixaDialeto>::from_iter(
648/// CaixaDialeto::ALL.iter().map(|d| (d.into(), *d)))`-style
649/// per-dialect reverse-lookup table the sibling [`TryFrom<&str>`] impl
650/// cannot compose without this borrowed-input axis in place) reaches the
651/// same four `"Pacote"` / `"Molde"` / `"MoldePosicional"` /
652/// `"Desconhecido"` byte-strings the paired owned-input
653/// [`From<CaixaDialeto> for &'static str`], the sibling
654/// [`std::fmt::Display`], [`AsRef<str>`], and [`CaixaDialeto::as_str`]
655/// surfaces already return.
656///
657/// Third peer on the substrate-wide trait-idiomatic *borrowed-input*
658/// forward-projection family opened on
659/// [`crate::dep::DepList`] (64aa742) and extended onto
660/// [`crate::CaixaKind`] (5ab993a). Rust's `From` trait does not
661/// auto-derive the `From<&Self>` sibling from a `From<Self>` impl (the
662/// blanket `impl<T, U> From<&T> for U where T: Copy, U: From<T>` does
663/// not exist in `core`), so every closed-set typed enum that carries
664/// the owned-input axis but not the borrowed-input axis forces every
665/// borrowed-input call site through a `.copied()` /
666/// `<&'static str>::from(*dialeto)` / `dialeto.as_str()` detour whose
667/// type bounds have no compile-time link to the substrate primitive.
668///
669/// Unlike the peer [`crate::CaixaKind`] impl (which carries a two-axis
670/// split between the lowercase Portuguese `as_str` diagnostic axis and
671/// the `PascalCase` `wire_name` author-surface axis, so a `.into()`
672/// pipe over `CaixaKind::ALL` yields the diagnostic vocabulary rather
673/// than the wire vocabulary), [`CaixaDialeto`]'s [`CaixaDialeto::as_str`]
674/// and [`CaixaDialeto::from_wire`] share the same `PascalCase`
675/// vocabulary by construction — the borrowed-input projection this impl
676/// exposes therefore composes directly with the sibling
677/// [`TryFrom<&str>`] axis to build reverse-lookup tables without the
678/// wire-vocab intermediate hop the peer axis pair requires.
679///
680/// Pinned load-bearing by
681/// [`tests::caixa_dialeto_from_borrowed_into_static_str_routes_through_as_str_accessor`]
682/// (byte-parity pin against [`CaixaDialeto::as_str`] across the four-arm
683/// emit-set via a borrowed input, plus a `const`-context materialization
684/// witness for the `&'static str` lifetime promise, plus a blanket
685/// `.into()` shape assertion) and
686/// [`tests::caixa_dialeto_from_owned_and_borrowed_into_static_str_agree_on_every_arm`]
687/// (cross-axis partition pin against the paired owned-input
688/// [`From<CaixaDialeto> for &'static str`] impl, plus a
689/// `.iter().map(Into::into)` pipe witness over [`CaixaDialeto::ALL`]
690/// that materializes the four-arm accept-set through the borrowed-input
691/// axis alone, plus a direct round-trip witness through the paired
692/// trait-idiomatic [`TryFrom<&str>`] axis that closes the two-way
693/// `&Self → &'static str → Self` round-trip on the borrowed-input axis
694/// without the wire-vocab intermediate the peer [`crate::CaixaKind`]
695/// axis pair requires).
696impl From<&CaixaDialeto> for &'static str {
697 fn from(dialeto: &CaixaDialeto) -> &'static str {
698 dialeto.as_str()
699 }
700}
701
702/// Trait-idiomatic *forward* projection on [`CaixaDialeto`] from an *owned*
703/// input onto the owned-[`String`] axis — routes byte-for-byte through the
704/// substrate-primitive [`CaixaDialeto::as_str`] `pub const fn` accessor so
705/// every consumer that binds a [`CaixaDialeto`] through the standard-library
706/// `.into()` / [`From<Self> for String`] (equivalently [`Into<String>`]) axis
707/// reaches the same four `"Pacote"` / `"Molde"` / `"MoldePosicional"` /
708/// `"Desconhecido"` byte-strings the paired owned-input
709/// [`From<CaixaDialeto> for &'static str`], the borrowed-input
710/// [`From<&CaixaDialeto> for &'static str`], the sibling [`std::fmt::Display`],
711/// [`AsRef<str>`], and [`CaixaDialeto::as_str`] surfaces already return.
712///
713/// Extends the trait-idiomatic *owned-[`String`]* forward-projection family
714/// (opened on [`crate::supervisor::RestartStrategy`] — 7baa18a — the first-
715/// mover on the M2 OTP-shape sibling-restart-strategy axis, extended onto
716/// [`crate::supervisor::RestartPolicy`] — 7851725 — the second-of-two-in-M2
717/// per-child restart-decision axis, then onto [`crate::CaixaKind`] — 231a18c
718/// — the structurally most fundamental closed-set fieldless typed enum on
719/// the caixa surface) onto the fourth peer: the dialect-classification axis
720/// [`CaixaDialeto`] carries. Rust's standard library does not carry a blanket
721/// `impl<T: AsRef<str>> From<T> for String` (nor an
722/// `impl<T: fmt::Display> From<T> for String`), so every closed-set typed
723/// enum that carries the paired `AsRef<str>` / `Display` /
724/// `From<Self> for &'static str` triple but not the owned-[`String`] axis
725/// forces every owned-string call site through a `.to_string()` /
726/// `.as_str().to_owned()` / `String::from(dialeto.as_str())` detour whose
727/// type bounds have no compile-time link to the substrate primitive.
728///
729/// Unlike the peer [`crate::CaixaKind`] enum (which carries a two-axis split
730/// between the lowercase Portuguese [`crate::CaixaKind::as_str`] diagnostic
731/// axis and the `PascalCase` [`crate::CaixaKind::wire_name`] author-surface
732/// axis, so the owned-[`String`] forward emit and the reverse
733/// [`TryFrom<&str>`] parse land on disjoint vocabularies and the round-trip
734/// crosses through [`crate::CaixaKind::wire_name`] as the reverse-axis
735/// vocabulary rather than composing the owned-[`String`] emit directly),
736/// [`CaixaDialeto`]'s [`CaixaDialeto::as_str`] emit and
737/// [`CaixaDialeto::from_wire`] parse share the same `PascalCase` vocabulary
738/// by construction (there is no wire/diagnostic axis split on this enum —
739/// it is an internal classification with no wire surface), so the
740/// owned-[`String`] forward projection this impl exposes composes directly
741/// with the sibling [`TryFrom<&str>`] axis on the owned-[`String`]'s
742/// [`String::as_str`] borrow, byte-identically to the peer
743/// [`crate::supervisor::RestartStrategy`] /
744/// [`crate::supervisor::RestartPolicy`] owned-[`String`] axis pairs
745/// (whose forward emit and reverse parse also share one `PascalCase`
746/// vocabulary by construction).
747///
748/// The remaining ten closed-set typed enums on the caixa substrate surface
749/// (`DepList`, `PlacementStrategy`, `WitShape`, `RateLimitUnit`,
750/// `PathShapeViolation`, `InvariantKind`, `ArchVerdict`, `Severity`,
751/// `FixSafety`, `Semantic`, `FerriteRuntime`) are the future targets of
752/// this campaign — each carries the same paired `AsRef<str>` / `Display` /
753/// `From<Self> for &'static str` / `From<&Self> for &'static str` quadruple
754/// that this owned-[`String`] axis extends onto.
755///
756/// Pinned load-bearing by
757/// [`tests::caixa_dialeto_from_into_owned_string_routes_through_as_str_accessor`]
758/// (byte-parity pin against [`CaixaDialeto::as_str`] across the four-arm
759/// emit-set, plus a blanket `.into::<String>()` shape witness) and
760/// [`tests::caixa_dialeto_from_into_owned_string_and_static_str_agree_on_every_arm`]
761/// (cross-axis partition pin against the paired owned-input
762/// [`From<CaixaDialeto> for &'static str`] impl and the sibling
763/// [`ToString::to_string`] surface routed through [`std::fmt::Display`],
764/// plus a `.iter().copied().map(String::from)` pipe witness over
765/// [`CaixaDialeto::ALL`], plus a direct round-trip witness through
766/// [`TryFrom<&str>`] on the owned-[`String`]'s [`String::as_str`] borrow
767/// that closes the two-way `Self → String → Self` round-trip on the
768/// trait-idiomatic owned-[`String`] forward + reverse axis pair without
769/// the wire-vocab intermediate hop the peer [`crate::CaixaKind`] axis pair
770/// requires).
771impl From<CaixaDialeto> for String {
772 fn from(dialeto: CaixaDialeto) -> String {
773 dialeto.as_str().to_owned()
774 }
775}
776
777/// Trait-idiomatic *borrowed-input, owned-`String` output* forward
778/// projection on the dialect-classification [`CaixaDialeto`] closed-set
779/// typed enum — the fourth (and closing) corner of the
780/// `{Self, &Self} × {&'static str, String}` 2×2 trait-idiomatic
781/// projection family on this enum, mirror of the peer M2 OTP-shape
782/// [`From<&crate::supervisor::RestartStrategy> for String`] (579385f) /
783/// [`From<&crate::supervisor::RestartPolicy> for String`] (8465740),
784/// the two-list dep-graph [`From<&crate::dep::DepList> for String`]
785/// (e0cb617), and the top-level [`From<&crate::CaixaKind> for String`]
786/// (e76436d) that opened and extended the corner off the M2 OTP-shape
787/// sibling axis pair onto the sibling closed-set fieldless typed enum
788/// peers. Routes byte-for-byte through the substrate-primitive
789/// [`CaixaDialeto::as_str`] `pub const fn` accessor (via
790/// [`str::to_owned`]) so every consumer that holds a borrowed
791/// [`&CaixaDialeto`] and needs an owned [`String`] — a future
792/// `serde_json::Value::String(String::from(&dialeto))` structured-
793/// payload composer over a borrowed field, a future `Iterator::map`
794/// over `&[CaixaDialeto]` that projects to owned keys through
795/// `.iter().map(String::from)` (whose iterator yields `&CaixaDialeto`,
796/// not `CaixaDialeto`, so the owned-input
797/// [`From<CaixaDialeto> for String`] axis alone forces every call site
798/// through an explicit `.copied()` / spurious [`Copy`] deref restatement
799/// rather than the direct trait-idiomatic projection), a future
800/// `HashMap::<String, CaixaDialeto>::from_iter` that keys off a
801/// borrowed-iteration axis where dereferencing the dialect would force
802/// an unnecessary [`Copy`] at every step, the future
803/// `feira dialeto --list-dialects` CLI enumeration that walks
804/// [`CaixaDialeto::ALL`] through the borrowed-iteration axis by
805/// construction, the future M4
806/// `mesh.pleme.io/v1alpha1/Manifesto` CR materializer's admission-
807/// webhook rejection body composer that names the accepted-dialect
808/// set through an iterated `.iter().map(String::from).collect()`
809/// pipe rather than a per-arm cascade — reaches the same four
810/// `"Pacote"` / `"Molde"` / `"MoldePosicional"` / `"Desconhecido"`
811/// byte-strings the paired [`std::fmt::Display`], [`AsRef<str>`],
812/// [`CaixaDialeto::as_str`], and the three other trait-idiomatic
813/// forward-projection impls ([`From<CaixaDialeto> for &'static str`],
814/// [`From<&CaixaDialeto> for &'static str`],
815/// [`From<CaixaDialeto> for String`]) already return.
816///
817/// Fifth peer on the substrate-wide trait-idiomatic *borrowed-input,
818/// owned-`String` output* forward-projection family opened on
819/// [`crate::supervisor::RestartStrategy`] (579385f), closed on the M2
820/// OTP-shape sibling axis pair by
821/// [`crate::supervisor::RestartPolicy`] (8465740), extended onto the
822/// two-list dep-graph peer by [`crate::dep::DepList`] (e0cb617) and
823/// onto the top-level [`crate::CaixaKind`] (e76436d) — extends the
824/// `{Self, &Self} × {&'static str, String}` 2×2 projection corner off
825/// the top-level `:kind` axis onto the dialect-classification axis
826/// (the fourth closed-set fieldless typed enum on the caixa surface;
827/// second peer outside the M2 OTP-shape sibling pair to reach the
828/// 2×2-completion corner). Rust's standard library does not carry a
829/// blanket `impl<T: AsRef<str>> From<&T> for String` (nor an
830/// `impl<T: fmt::Display> From<&T> for String`), so every closed-set
831/// typed enum that carries the paired `AsRef<str>` / `Display` /
832/// `From<Self> for &'static str` / `From<&Self> for &'static str` /
833/// `From<Self> for String` quintuple but not the borrowed-input
834/// owned-[`String`] axis forces every borrowed-input owned-string call
835/// site through a `dialeto.as_str().to_owned()` /
836/// `String::from(*dialeto)` (with a spurious [`Copy`]) /
837/// `dialeto.to_string()` (through [`std::fmt::Display`]) detour whose
838/// type bounds have no compile-time link to the substrate primitive.
839///
840/// Same as the peer [`crate::supervisor::RestartStrategy`] /
841/// [`crate::supervisor::RestartPolicy`] / [`crate::dep::DepList`]
842/// borrowed-input owned-[`String`] axis pairs (whose forward emit and
843/// reverse parse share one vocabulary by construction — `PascalCase`
844/// on the M2 OTP-shape peers, the lifted
845/// [`crate::render::DEP_AUTHOR_KEY_DEPS`] /
846/// [`crate::render::DEP_AUTHOR_KEY_DEPS_DEV`] consts on the two-list
847/// dep-graph peer) and unlike the peer [`crate::CaixaKind`] pair
848/// (whose forward emit lands on the lowercase Portuguese
849/// diagnostic vocabulary while the reverse parse lands on the
850/// `PascalCase` wire vocabulary, forcing the round-trip through an
851/// intermediate [`crate::CaixaKind::wire_name`] hop), [`CaixaDialeto`]
852/// is an internal classification with no wire surface — the
853/// [`CaixaDialeto::as_str`] emit and [`CaixaDialeto::from_wire`] parse
854/// share the same `PascalCase` vocabulary by construction (there is
855/// no wire/diagnostic axis split on this enum), so the borrowed-
856/// input owned-[`String`] projection this impl exposes composes
857/// directly with the paired trait-idiomatic reverse [`TryFrom<&str>`]
858/// axis on the owned-[`String`]'s [`String::as_str`] borrow — no
859/// intermediate wire-vocab hop required.
860///
861/// The remaining nine closed-set typed enums on the caixa substrate
862/// surface (`PlacementStrategy`, `WitShape`, `RateLimitUnit`,
863/// `PathShapeViolation`, `InvariantKind`, `ArchVerdict`, `Severity`,
864/// `FixSafety`, `Semantic`, `FerriteRuntime`) are the future targets
865/// of this 2×2-completion campaign — each carries the same paired
866/// quintuple that this borrowed-input owned-[`String`] axis extends
867/// onto.
868///
869/// Pinned load-bearing by
870/// [`tests::caixa_dialeto_from_into_borrowed_owned_string_routes_through_as_str_accessor`]
871/// (byte-parity pin against [`CaixaDialeto::as_str`] across the
872/// four-arm emit-set through the borrowed-input surface) and
873/// [`tests::caixa_dialeto_from_into_borrowed_owned_string_agrees_with_paired_axes_on_every_arm`]
874/// (cross-axis partition pin against the paired owned-input owned-
875/// [`String`] [`From<CaixaDialeto> for String`] impl, the paired
876/// borrowed-input owned-[`&'static str`]
877/// [`From<&CaixaDialeto> for &'static str`] impl, the paired owned-
878/// input owned-[`&'static str`] [`From<CaixaDialeto> for &'static str`]
879/// impl, and the sibling [`ToString::to_string`] surface routed
880/// through [`std::fmt::Display`], plus a `.iter().map(String::from)`
881/// pipe witness over [`CaixaDialeto::ALL`] (whose iterator yields
882/// `&CaixaDialeto` by construction, so the borrowed-input owned-
883/// [`String`] axis is what routes the pipe through the substrate-
884/// primitive [`CaixaDialeto::as_str`] accessor without a spurious
885/// [`Copy`] deref), plus a direct round-trip witness through
886/// [`TryFrom<&str>`] on the owned-[`String`]'s [`String::as_str`]
887/// borrow that closes the two-way `&Self → String → Self` round-trip
888/// on the trait-idiomatic borrowed-input owned-[`String`] forward +
889/// reverse axis pair — no intermediate wire-vocab hop like the peer
890/// [`crate::CaixaKind`] axis pair requires).
891impl From<&CaixaDialeto> for String {
892 fn from(dialeto: &CaixaDialeto) -> String {
893 dialeto.as_str().to_owned()
894 }
895}
896
897/// Trait-idiomatic *owned-input, [`std::borrow::Cow<'static, str>`]
898/// output* forward projection on the dialect-classification
899/// [`CaixaDialeto`] closed-set typed enum — routes byte-for-byte
900/// through the substrate-primitive [`CaixaDialeto::as_str`]
901/// `pub const fn` accessor (via [`std::borrow::Cow::Borrowed`]) so
902/// every consumer that binds a [`CaixaDialeto`] through the
903/// standard-library `.into()` /
904/// [`From<Self> for std::borrow::Cow<'static, str>`] (equivalently
905/// [`Into<std::borrow::Cow<'static, str>>`]) axis — a future
906/// `axum::response::IntoResponse` body composer whose typing folds a
907/// per-arm rejection line into a [`std::borrow::Cow<'static, str>`]
908/// boundary, a future M4 `mesh.pleme.io/v1alpha1/Manifesto` CR
909/// materializer's admission-webhook rejection body composer whose
910/// typing rules out the sibling [`AsRef<str>`] borrowed return and
911/// the sibling [`From<Self> for &'static str`] axis's non-
912/// [`std::borrow::Cow`]-parameterized shape, a future substrate-wide
913/// per-arm diagnostic surface that folds either the zero-alloc
914/// [`std::borrow::Cow::Borrowed`] arm (for the closed-set arms whose
915/// byte-string is build-time-lifted) or the [`std::borrow::Cow::Owned`]
916/// arm (for a caller that mutates the projection) through one uniform
917/// trait dispatch, a future generic
918/// `<T: Into<std::borrow::Cow<'static, str>>>`-bound emitter on a
919/// per-dialect structured-log or admission-webhook rejection body —
920/// reaches the same four `"Pacote"` / `"Molde"` / `"MoldePosicional"` /
921/// `"Desconhecido"` byte-strings the paired [`std::fmt::Display`],
922/// [`AsRef<str>`], [`CaixaDialeto::as_str`], and the four
923/// `{Self, &Self} × {&'static str, String}` 2×2 trait-idiomatic
924/// forward-projection corners
925/// ([`From<CaixaDialeto> for &'static str`],
926/// [`From<&CaixaDialeto> for &'static str`],
927/// [`From<CaixaDialeto> for String`],
928/// [`From<&CaixaDialeto> for String`]) already return, rather than an
929/// open-coded per-call-site
930/// `std::borrow::Cow::Borrowed(dialeto.as_str())` /
931/// `std::borrow::Cow::Owned(dialeto.to_string())` /
932/// `String::from(dialeto).into()` composition whose type bounds have
933/// no compile-time link back to the substrate primitive.
934///
935/// Deliberately returns [`std::borrow::Cow::Borrowed`] rather than
936/// [`std::borrow::Cow::Owned`] — the substrate-primitive
937/// [`CaixaDialeto::as_str`] accessor's return carries the
938/// `&'static str` lifetime by construction (each `match` arm resolves
939/// to a `pub const &'static str` literal with static lifetime), so the
940/// zero-alloc borrowed arm is the type-correct projection with no
941/// runtime allocation. The paired [`std::borrow::Cow::Owned`] arm
942/// stays reachable at the call site through the existing
943/// [`From<CaixaDialeto> for String`] axis composed with
944/// [`std::borrow::Cow::from`] on the resulting owned [`String`] — a
945/// caller who chose to mutate the projection lands on the owned arm
946/// by their own composition, not by the substrate-primitive
947/// projection silently allocating on their behalf.
948///
949/// Same as the sibling [`crate::CaixaKind`] /
950/// [`crate::supervisor::RestartStrategy`] /
951/// [`crate::supervisor::RestartPolicy`] /
952/// [`crate::aplicacao::WitShape`] /
953/// [`crate::aplicacao::PlacementStrategy`] /
954/// [`crate::aplicacao::RateLimitUnit`] /
955/// [`crate::dep::DepList`] peers on the substrate-wide trait-idiomatic
956/// [`std::borrow::Cow<'static, str>`] forward-projection campaign,
957/// unlike the peer [`crate::CaixaKind`] pair (whose forward emit
958/// lands on the lowercase Portuguese diagnostic vocabulary while the
959/// reverse parse lands on the `PascalCase` wire vocabulary, forcing
960/// the round-trip through an intermediate
961/// [`crate::CaixaKind::wire_name`] hop), [`CaixaDialeto`] is an
962/// internal classification with no wire surface — the
963/// [`CaixaDialeto::as_str`] emit and [`CaixaDialeto::from_wire`]
964/// parse share the same `PascalCase` vocabulary by construction (no
965/// wire/diagnostic axis split on this enum), so the
966/// [`std::borrow::Cow<'static, str>`] projection this impl exposes
967/// composes directly with the paired trait-idiomatic reverse
968/// [`TryFrom<&str>`] axis on the projection's
969/// [`std::borrow::Cow::as_ref`] borrow — no intermediate wire-vocab
970/// hop required.
971///
972/// Eighth peer on the substrate-wide trait-idiomatic
973/// [`std::borrow::Cow<'static, str>`] forward-projection family
974/// opened on the top-level [`crate::CaixaKind`] by 99c1735 (extended
975/// off the closed `{Self, &Self} × {&'static str, String}` 2×2
976/// corner closed on the last outside-caixa-core enum peer by
977/// 29f8af3), closed on the `{Self, &Self}` input-shape corner on
978/// [`crate::CaixaKind`] by d45c409, extended onto the M2 OTP-shape
979/// tier by 7dd28b3 / 9b3e4b3 (opens/closes on
980/// [`crate::supervisor::RestartStrategy`]) and 0612398 / ee577fd
981/// (opens/closes on [`crate::supervisor::RestartPolicy`], closing the
982/// M2 OTP-shape tier), extended onto the M3 mesh-shape tier by
983/// 8634dec / 25690ef (opens/closes on [`crate::aplicacao::WitShape`])
984/// and eee504d / afdf0f4 (opens/closes on
985/// [`crate::aplicacao::PlacementStrategy`]) and 1d59925 (closes M3
986/// mesh-shape tier on [`crate::aplicacao::RateLimitUnit`]), extended
987/// onto the outside-M3 caixa-core tier by 6858bac / 702cdf4
988/// (opens/closes on [`crate::dep::DepList`]) — extends the axis onto
989/// the dialect-classification [`CaixaDialeto`] closed-set fieldless
990/// typed enum (the second outside-M3 caixa-core peer, and the sole
991/// remaining internal-classification enum on the caixa-core surface).
992/// Rust's standard library does not carry a blanket
993/// `impl<T: AsRef<str>> From<T> for std::borrow::Cow<'static, str>`
994/// (nor an `impl<T: fmt::Display> From<T> for
995/// std::borrow::Cow<'static, str>`), so every closed-set fieldless
996/// typed enum peer on the substrate that carries the paired
997/// [`AsRef<str>`] / [`std::fmt::Display`] /
998/// [`From<Self> for &'static str`] / [`From<&Self> for &'static str`]
999/// / [`From<Self> for String`] / [`From<&Self> for String`] sextet but
1000/// not the [`std::borrow::Cow<'static, str>`] axis forces every
1001/// [`std::borrow::Cow<'static, str>`]-parameterized call site through
1002/// a `std::borrow::Cow::Borrowed(dialeto.as_str())` /
1003/// `std::borrow::Cow::Owned(dialeto.to_string())` /
1004/// `String::from(dialeto).into()` detour whose type bounds have no
1005/// compile-time link to the substrate primitive.
1006///
1007/// The remaining outside-`caixa-core` closed-set fieldless typed
1008/// enum peers on the substrate surface (`PathShapeViolation`,
1009/// `InvariantKind`, `ArchVerdict`, `Severity`, `FixSafety`,
1010/// `Semantic`, `FerriteRuntime`) are the future targets of this
1011/// campaign — each carries the same paired sextet that this axis
1012/// extends onto.
1013///
1014/// Pinned load-bearing by
1015/// [`tests::caixa_dialeto_from_into_static_cow_str_routes_through_as_str_accessor`]
1016/// (byte-parity pin against [`CaixaDialeto::as_str`] across the
1017/// four-arm emit-set through the [`std::borrow::Cow<'static, str>`]
1018/// surface, plus a [`std::borrow::Cow::Borrowed`] discriminator
1019/// witness that the projection lands on the zero-alloc arm rather
1020/// than silently allocating through [`std::borrow::Cow::Owned`],
1021/// plus a blanket-derived [`Into<std::borrow::Cow<'static, str>>`]
1022/// shape witness that also lands on [`std::borrow::Cow::Borrowed`])
1023/// and
1024/// [`tests::caixa_dialeto_from_into_static_cow_str_agrees_with_paired_axes_on_every_arm`]
1025/// (cross-axis partition pin against the paired owned-input
1026/// [`From<CaixaDialeto> for &'static str`] and
1027/// [`From<CaixaDialeto> for String`] forward-projection corners plus
1028/// the sibling [`ToString::to_string`]-through-[`std::fmt::Display`]
1029/// surface, plus a `.iter().copied().map(std::borrow::Cow::from)`
1030/// pipe witness over [`CaixaDialeto::ALL`] whose zero-alloc
1031/// [`std::borrow::Cow::Borrowed`] outcome is load-bearing on every
1032/// arm, plus a direct round-trip witness through [`TryFrom<&str>`]
1033/// on the projection's [`std::borrow::Cow::as_ref`] borrow that
1034/// closes the two-way `Self → Cow<'static, str> → Self` round-trip
1035/// on the trait-idiomatic [`std::borrow::Cow<'static, str>`]
1036/// forward + reverse axis pair without the wire-vocab intermediate
1037/// hop the peer [`crate::CaixaKind`] axis pair requires).
1038impl From<CaixaDialeto> for std::borrow::Cow<'static, str> {
1039 fn from(dialeto: CaixaDialeto) -> std::borrow::Cow<'static, str> {
1040 std::borrow::Cow::Borrowed(dialeto.as_str())
1041 }
1042}
1043
1044/// Trait-idiomatic *borrowed-input, [`std::borrow::Cow<'static, str>`]
1045/// output* forward projection on the dialect-classification
1046/// [`CaixaDialeto`] closed-set typed enum — the borrowed-input companion
1047/// to the paired owned-input [`From<CaixaDialeto> for
1048/// std::borrow::Cow<'static, str>`] impl immediately above (8322511).
1049/// Routes byte-for-byte through the same substrate-primitive
1050/// [`CaixaDialeto::as_str`] `pub const fn` accessor (via
1051/// [`std::borrow::Cow::Borrowed`]) so every consumer that holds a
1052/// [`&CaixaDialeto`] and needs a [`std::borrow::Cow<'static, str>`] — a
1053/// `CaixaDialeto::ALL.iter().map(std::borrow::Cow::from).collect::<Vec<_>>()`
1054/// per-arm accept-set materializer whose iterator over
1055/// `&'static [CaixaDialeto]` yields `&CaixaDialeto` (not
1056/// [`CaixaDialeto`], so the paired owned-input
1057/// [`From<CaixaDialeto> for std::borrow::Cow<'static, str>`] axis alone
1058/// forces every call site through an explicit `.copied()` / dereference
1059/// / [`Copy`]-bound restatement rather than the direct trait-idiomatic
1060/// projection), a future generic
1061/// `<T: for<'a> Into<std::borrow::Cow<'static, str>>>`-bound emitter on
1062/// a per-dialect diagnostic column that walks the
1063/// `iter().map(Into::into)` shape verbatim, the future M4
1064/// `mesh.pleme.io/v1alpha1/Manifesto` CR admission-webhook rejection
1065/// body that composes the accepted-dialect enumeration from an iterated
1066/// `CaixaDialeto::ALL.iter().map(|d| d.into())` pipe rather than a
1067/// per-arm `match d { … }` cascade — reaches the same four `"Pacote"` /
1068/// `"Molde"` / `"MoldePosicional"` / `"Desconhecido"` byte-strings the
1069/// paired [`std::fmt::Display`], [`AsRef<str>`], [`CaixaDialeto::as_str`],
1070/// the four `{Self, &Self} × {&'static str, String}` 2×2 trait-idiomatic
1071/// forward-projection corners, and the paired owned-input
1072/// [`From<CaixaDialeto> for std::borrow::Cow<'static, str>`] impl
1073/// already return.
1074///
1075/// Deliberately returns [`std::borrow::Cow::Borrowed`] rather than
1076/// [`std::borrow::Cow::Owned`] — the substrate-primitive
1077/// [`CaixaDialeto::as_str`] accessor's return carries the `&'static str`
1078/// lifetime by construction (each `match` arm resolves to a `pub const
1079/// &'static str` literal), so the zero-alloc borrowed arm is the
1080/// type-correct projection with no runtime allocation on the
1081/// borrowed-input surface just as on the paired owned-input surface.
1082///
1083/// Closes the `{Self, &Self}` input-shape corner on the second
1084/// outside-M3 caixa-core peer of the substrate-wide
1085/// [`std::borrow::Cow<'static, str>`] forward-projection campaign,
1086/// opened one commit prior (8322511) on the paired owned-input impl.
1087/// Rust's standard library does not carry a blanket
1088/// `impl<T: AsRef<str>> From<&T> for std::borrow::Cow<'static, str>`
1089/// (nor an `impl<T: fmt::Display> From<&T> for
1090/// std::borrow::Cow<'static, str>`, nor a `Copy`-based
1091/// `impl<T: Copy, U: From<T>> From<&T> for U`), so every closed-set
1092/// fieldless typed enum peer on the substrate that carries the paired
1093/// owned-input [`Cow<'static, str>`] axis but not the borrowed-input
1094/// axis forces every borrowed-input [`Cow<'static, str>`]-parameterized
1095/// call site through a spurious [`Copy`] deref
1096/// (`std::borrow::Cow::from(*dialeto)`) or a
1097/// `std::borrow::Cow::Borrowed(dialeto.as_str())` open-code whose type
1098/// bounds have no compile-time link to the substrate primitive.
1099///
1100/// Matches the closure discipline afdf0f4 landed on the M3-mesh-shape
1101/// [`crate::aplicacao::PlacementStrategy`] axis one commit after eee504d,
1102/// 25690ef on [`crate::aplicacao::WitShape`] one commit after 8634dec,
1103/// d45c409 on the top-level [`crate::CaixaKind`] one commit after
1104/// 99c1735, 9b3e4b3 / ee577fd on the M2 OTP-shape
1105/// [`crate::supervisor::RestartStrategy`] /
1106/// [`crate::supervisor::RestartPolicy`] sibling peers one commit after
1107/// 7dd28b3 / 0612398, and 702cdf4 on the two-list dep-graph
1108/// [`crate::dep::DepList`] axis one commit after 6858bac. The remaining
1109/// outside-M3 caixa-core peer ([`crate::render::PathShapeViolation`])
1110/// and the outside-`caixa-core` peers (`InvariantKind`, `ArchVerdict`,
1111/// `Severity`, `FixSafety`, `Semantic`, `FerriteRuntime`) are the
1112/// remaining future targets on the axis.
1113///
1114/// Unlike the peer [`crate::CaixaKind`] pair (whose forward emit lands
1115/// on the lowercase Portuguese diagnostic vocabulary while the reverse
1116/// parse lands on the `PascalCase` wire vocabulary, forcing the
1117/// round-trip through an intermediate [`crate::CaixaKind::wire_name`]
1118/// hop), [`CaixaDialeto`] is an internal classification with no wire
1119/// surface — the [`CaixaDialeto::as_str`] emit and
1120/// [`CaixaDialeto::from_wire`] parse share the same `PascalCase`
1121/// vocabulary by construction (no wire/diagnostic axis split on this
1122/// enum), so the borrowed-input [`std::borrow::Cow<'static, str>`]
1123/// projection this impl exposes composes directly with the paired
1124/// trait-idiomatic reverse [`TryFrom<&str>`] axis on the projection's
1125/// [`std::borrow::Cow::as_ref`] borrow — no intermediate wire-vocab hop
1126/// required.
1127///
1128/// Pinned load-bearing by
1129/// [`tests::caixa_dialeto_from_borrowed_into_static_cow_str_routes_through_as_str_accessor`]
1130/// (byte-parity + zero-alloc [`std::borrow::Cow::Borrowed`]-arm pin
1131/// against [`CaixaDialeto::as_str`] across the four-arm
1132/// [`CaixaDialeto::ALL`] through the borrowed-input surface, plus a
1133/// blanket-derived [`Into<std::borrow::Cow<'static, str>>`] shape
1134/// witness that also lands on [`std::borrow::Cow::Borrowed`]) and
1135/// [`tests::caixa_dialeto_from_borrowed_into_static_cow_str_agrees_with_paired_axes_on_every_arm`]
1136/// (cross-axis partition pin against the paired owned-input
1137/// [`From<CaixaDialeto> for std::borrow::Cow<'static, str>`], the paired
1138/// borrowed-input owned-`&'static str`
1139/// [`From<&CaixaDialeto> for &'static str`], and the paired
1140/// borrowed-input owned-`String` [`From<&CaixaDialeto> for String`]
1141/// impls plus [`ToString::to_string`]-through-[`std::fmt::Display`], a
1142/// `.iter().map(std::borrow::Cow::from)` pipe witness over
1143/// [`CaixaDialeto::ALL`] — whose iterator yields `&CaixaDialeto` by
1144/// construction, so the borrowed-input axis is what routes the pipe
1145/// without a spurious [`Copy`] deref and every collected element
1146/// satisfies the zero-alloc [`std::borrow::Cow::Borrowed`]-arm
1147/// predicate — plus a direct round-trip witness through
1148/// [`TryFrom<&str>`] on the projection's [`std::borrow::Cow::as_ref`]
1149/// borrow that closes the two-way `&Self → Cow<'static, str> → Self`
1150/// round-trip on the borrowed-input axis without the wire-vocab
1151/// intermediate hop the peer [`crate::CaixaKind`] axis pair requires).
1152impl From<&CaixaDialeto> for std::borrow::Cow<'static, str> {
1153 fn from(dialeto: &CaixaDialeto) -> std::borrow::Cow<'static, str> {
1154 std::borrow::Cow::Borrowed(dialeto.as_str())
1155 }
1156}
1157
1158/// Trait-idiomatic *owned-input, [`Box<str>`] output* forward projection on
1159/// the outside-M3 caixa-core dialect-classification [`CaixaDialeto`]
1160/// closed-set fieldless typed enum. Routes byte-for-byte through the
1161/// substrate-primitive [`CaixaDialeto::as_str`] `pub const fn` accessor
1162/// via [`Box::<str>::from`] on the returned `&'static str`, so every
1163/// consumer that binds a `let key: Box<str> = dialeto.into();`-shaped
1164/// call site reaches the same four `"Pacote"` / `"Molde"` /
1165/// `"MoldePosicional"` / `"Desconhecido"` byte-strings the sibling
1166/// `{Self, &Self} × {&'static str, String, Cow<'static, str>}` forward-
1167/// projection corner already returns.
1168///
1169/// Rust's standard library carries `impl From<&str> for Box<str>` and
1170/// `impl From<String> for Box<str>` but no blanket
1171/// `impl<T: AsRef<str>> From<T> for Box<str>`, so this axis is a distinct
1172/// trait-idiomatic surface that a downstream `CaixaDialeto → Box<str>`
1173/// `.into()` reaches through this impl and no other — without a
1174/// `Box::from(dialeto.as_str())` open-code whose type bounds have no
1175/// compile-time link back to the substrate primitive.
1176///
1177/// Extends the caixa-core-internal tier of the substrate-wide trait-
1178/// idiomatic [`Box<str>`] forward-projection campaign onto the third
1179/// caixa-core-internal peer, after the render-side path-shape-diagnostic
1180/// [`crate::render::PathShapeViolation`] pair (0d87a72, both corners in
1181/// one axis) opened the tier and the outside-M3 caixa-core two-list
1182/// dep-graph [`crate::dep::DepList`] pair (4aada99, both corners in one
1183/// axis) extended it. Follows the M2 OTP-shape
1184/// [`crate::supervisor::RestartStrategy`] / [`crate::supervisor::RestartPolicy`]
1185/// pair (59ae5dc + cb1d068), the M3 mesh-shape
1186/// [`crate::aplicacao::PlacementStrategy`] / [`crate::aplicacao::WitShape`] /
1187/// [`crate::aplicacao::RateLimitUnit`] triple (6d73e84 → df7040c) that
1188/// closed the M3 mesh-shape tier, and the outside-`caixa-core` tier
1189/// (`InvariantKind` 10613a7 + 5901887, `ArchVerdict` 3e08f5a + c4319a8,
1190/// `Severity` 5116c95, `FixSafety` cf0174b, `Semantic` 0cd7dc3,
1191/// `FerriteRuntime` 14886a8) that closed one tier prior. Same discipline
1192/// as those peers: forward emit (this impl, the sibling `{&'static str,
1193/// String, Cow<'static, str>}` forward-projection corner,
1194/// [`std::fmt::Display`], [`AsRef<str>`], [`CaixaDialeto::as_str`]) and
1195/// reverse parse ([`CaixaDialeto::from_wire`], [`TryFrom<&str>`]) route
1196/// through the same four `PascalCase` byte-strings by construction, so
1197/// the round-trip composes directly without the wire-vocab intermediate
1198/// hop the peer [`crate::CaixaKind`] axis pair requires.
1199///
1200/// A future arm addition (the module doc's "third dialect" hazard
1201/// actualising as a fifth arm) reaches the paired [`Box<str>`] output
1202/// axis through one match-arm edit on the [`CaixaDialeto::as_str`]
1203/// `pub const fn` accessor, not a coordinated rewrite of every
1204/// downstream `Box::from(dialeto.as_str())` open-code.
1205///
1206/// Pinned load-bearing by
1207/// [`tests::caixa_dialeto_from_into_box_str_routes_through_as_str_accessor`]
1208/// (byte-parity pin against [`CaixaDialeto::as_str`] across the four-arm
1209/// [`CaixaDialeto::ALL`] emit-set on the owned-input surface, plus a
1210/// blanket-derived [`Into`] shape witness).
1211impl From<CaixaDialeto> for Box<str> {
1212 fn from(dialeto: CaixaDialeto) -> Box<str> {
1213 Box::<str>::from(dialeto.as_str())
1214 }
1215}
1216
1217/// Trait-idiomatic *borrowed-input, [`Box<str>`] output* forward projection
1218/// on the outside-M3 caixa-core dialect-classification [`CaixaDialeto`]
1219/// closed-set fieldless typed enum. Routes byte-for-byte through the
1220/// substrate-primitive [`CaixaDialeto::as_str`] `pub const fn` accessor
1221/// via [`Box::<str>::from`] on the returned `&'static str`, so every
1222/// consumer that binds a `let key: Box<str> = (&dialeto).into();`-shaped
1223/// call site or a `CaixaDialeto::ALL.iter().map(Box::<str>::from)`-shaped
1224/// pipe (whose iterator over `&'static [CaixaDialeto]` yields
1225/// `&CaixaDialeto` by construction) reaches the same four `"Pacote"` /
1226/// `"Molde"` / `"MoldePosicional"` / `"Desconhecido"` byte-strings the
1227/// sibling `{Self, &Self} × {&'static str, String, Cow<'static, str>}`
1228/// forward-projection corner and the paired owned-input
1229/// [`From<CaixaDialeto> for Box<str>`] already return.
1230///
1231/// Rust's standard library carries `impl From<&str> for Box<str>` and
1232/// `impl From<String> for Box<str>` but no blanket
1233/// `impl<T: AsRef<str>> From<&T> for Box<str>` (nor a `Copy`-based
1234/// `impl<T: Copy, U: From<T>> From<&T> for U`), so this borrowed-input
1235/// axis is a distinct trait-idiomatic surface that the pipe shape
1236/// [`CaixaDialeto::ALL`]`.iter().map(Box::<str>::from)` reaches through
1237/// this impl and no other — without it, the same pipe would force an
1238/// explicit `.copied()` restatement whose type bounds have no compile-
1239/// time link back to the substrate primitive, and a
1240/// `let key: Box<str> = (&dialeto).into();`-shaped call site would force
1241/// an explicit `Copy` deref (`Box::<str>::from(*dialeto)`) or a
1242/// `Box::<str>::from(dialeto.as_str())` open-code with the same defect.
1243///
1244/// Closes the `{Self, &Self}` input-shape corner on the third caixa-
1245/// core-internal closed-set fieldless typed enum peer of the substrate-
1246/// wide trait-idiomatic [`Box<str>`] forward-projection campaign,
1247/// matching the trajectory the paired render-side path-shape-diagnostic
1248/// [`crate::render::PathShapeViolation`] pair (0d87a72, both corners in
1249/// one axis) and the paired outside-M3 caixa-core two-list dep-graph
1250/// [`crate::dep::DepList`] pair (4aada99, both corners in one axis)
1251/// walked before it.
1252///
1253/// Pinned load-bearing by
1254/// [`tests::caixa_dialeto_from_borrowed_into_box_str_routes_through_as_str_accessor`]
1255/// (byte-parity pin against [`CaixaDialeto::as_str`] across the four-arm
1256/// [`CaixaDialeto::ALL`] emit-set on the borrowed-input surface, plus a
1257/// blanket-derived [`Into`] shape witness, plus a
1258/// `.iter().map(Box::<str>::from)` pipe witness over
1259/// [`CaixaDialeto::ALL`] — whose iterator yields `&CaixaDialeto` by
1260/// construction, so the borrowed-input [`Box<str>`] axis is what routes
1261/// the pipe through the substrate-primitive [`CaixaDialeto::as_str`]
1262/// accessor without a spurious [`Copy`] deref).
1263impl From<&CaixaDialeto> for Box<str> {
1264 fn from(dialeto: &CaixaDialeto) -> Box<str> {
1265 Box::<str>::from(dialeto.as_str())
1266 }
1267}
1268
1269/// Trait-idiomatic *owned-input, [`std::sync::Arc<str>`] output* forward
1270/// projection on the outside-M3 caixa-core dialect-classification
1271/// [`CaixaDialeto`] closed-set fieldless typed enum. Routes byte-for-byte
1272/// through the substrate-primitive [`CaixaDialeto::as_str`] `pub const fn`
1273/// accessor via [`std::sync::Arc::<str>::from`] on the returned
1274/// `&'static str`, so every consumer that binds a
1275/// `let key: std::sync::Arc<str> = dialeto.into();`-shaped call site
1276/// reaches the same four `"Pacote"` / `"Molde"` / `"MoldePosicional"` /
1277/// `"Desconhecido"` byte-strings the sibling
1278/// `{Self, &Self} × {&'static str, String, Cow<'static, str>, Box<str>}`
1279/// forward-projection corner already returns.
1280///
1281/// Rust's standard library carries `impl From<&str> for std::sync::Arc<str>`
1282/// and `impl From<String> for std::sync::Arc<str>` but no blanket
1283/// `impl<T: AsRef<str>> From<T> for std::sync::Arc<str>` (nor an
1284/// `impl<T: fmt::Display> From<T> for std::sync::Arc<str>`), so this axis is
1285/// a distinct trait-idiomatic surface that a downstream
1286/// `CaixaDialeto → std::sync::Arc<str>` `.into()` reaches through this impl
1287/// and no other — a paired `std::sync::Arc::<str>::from(dialeto.as_str())`
1288/// open-code has no compile-time link back to the substrate primitive, and
1289/// a two-step `std::sync::Arc::<str>::from(String::from(dialeto))`
1290/// composition through the owned-`String` axis allocates twice (once into
1291/// the intermediate `String`, once into the [`std::sync::Arc<str>`] on the
1292/// `From<String>` conversion) where the single-step trait impl allocates
1293/// once.
1294///
1295/// Extends the caixa-core-internal tier of the substrate-wide trait-
1296/// idiomatic [`std::sync::Arc<str>`] forward-projection campaign onto the
1297/// third caixa-core-internal peer, after the structurally most fundamental
1298/// [`crate::CaixaKind`] pair (c17be64, both corners in one axis) opened the
1299/// tier and the outside-M3 two-list dep-graph [`crate::dep::DepList`] pair
1300/// (d8a4652, both corners in one axis) extended it. Follows the M2
1301/// OTP-shape [`crate::supervisor::RestartStrategy`] /
1302/// [`crate::supervisor::RestartPolicy`] pair (bca2ec8 → ea91551), the M3
1303/// mesh-shape [`crate::aplicacao::PlacementStrategy`] /
1304/// [`crate::aplicacao::WitShape`] / [`crate::aplicacao::RateLimitUnit`]
1305/// triple (977d577 → dae722f) that closed the M3 mesh-shape tier, and the
1306/// outside-`caixa-core` tier (`InvariantKind` 4e923c1 + 03c043f,
1307/// `ArchVerdict` 1682f8b + 92ddfb2, `Severity` a7a9a6d + 4f041e1,
1308/// `FixSafety` fb73edb + 822138e, `Semantic` 65dbcff + f3a55c7,
1309/// `FerriteRuntime` 938d915 + 0afef4b) that closed one tier prior. The
1310/// shared-ownership + [`Sync`] + [`Send`] contract [`std::sync::Arc<str>`]
1311/// provides is what makes the per-arm canonical dialect-classification
1312/// label safely reachable off both input-shape axes without a `.clone()`-
1313/// per-task materialization, distinct from the sibling [`Box<str>`] axis's
1314/// owned-move-only contract.
1315///
1316/// A future arm addition (the module doc's "third dialect" hazard
1317/// actualising as a fifth arm) reaches the paired [`std::sync::Arc<str>`]
1318/// output axis through one match-arm edit on the [`CaixaDialeto::as_str`]
1319/// `pub const fn` accessor, not a coordinated rewrite of every downstream
1320/// `std::sync::Arc::<str>::from(dialeto.as_str())` open-code.
1321///
1322/// Pinned load-bearing by
1323/// [`tests::caixa_dialeto_from_into_arc_str_routes_through_as_str_accessor`]
1324/// (byte-parity pin against [`CaixaDialeto::as_str`] across the four-arm
1325/// [`CaixaDialeto::ALL`] emit-set on the owned-input surface, plus a
1326/// blanket-derived [`Into`] shape witness and cross-axis byte-parity pins
1327/// against the sibling owned-input
1328/// `{&'static str, String, Cow<'static, str>, Box<str>}` return-shape axes).
1329impl From<CaixaDialeto> for std::sync::Arc<str> {
1330 fn from(dialeto: CaixaDialeto) -> std::sync::Arc<str> {
1331 std::sync::Arc::<str>::from(dialeto.as_str())
1332 }
1333}
1334
1335/// Trait-idiomatic *borrowed-input, [`std::sync::Arc<str>`] output* forward
1336/// projection on the outside-M3 caixa-core dialect-classification
1337/// [`CaixaDialeto`] closed-set fieldless typed enum — the borrowed-input
1338/// companion to the paired owned-input
1339/// [`From<CaixaDialeto> for std::sync::Arc<str>`] impl one commit above
1340/// that extends the caixa-core-internal tier of the substrate-wide trait-
1341/// idiomatic [`std::sync::Arc<str>`] forward-projection campaign onto the
1342/// third caixa-core-internal peer. Routes byte-for-byte through the
1343/// substrate-primitive [`CaixaDialeto::as_str`] `pub const fn` accessor via
1344/// [`std::sync::Arc::<str>::from`] on the returned `&'static str`, so every
1345/// consumer that binds a `let key: std::sync::Arc<str> = (&dialeto).into();`
1346/// -shaped call site or a
1347/// `CaixaDialeto::ALL.iter().map(std::sync::Arc::<str>::from)`-shaped pipe
1348/// (whose iterator over `&'static [CaixaDialeto]` yields `&CaixaDialeto` by
1349/// construction) reaches the same four `"Pacote"` / `"Molde"` /
1350/// `"MoldePosicional"` / `"Desconhecido"` byte-strings the sibling
1351/// `{Self, &Self} × {&'static str, String, Cow<'static, str>, Box<str>}`
1352/// forward-projection corner and the paired owned-input
1353/// [`From<CaixaDialeto> for std::sync::Arc<str>`] already return.
1354///
1355/// Rust's standard library carries `impl From<&str> for std::sync::Arc<str>`
1356/// and `impl From<String> for std::sync::Arc<str>` but no blanket
1357/// `impl<T: AsRef<str>> From<&T> for std::sync::Arc<str>` (nor a `Copy`-
1358/// based `impl<T: Copy, U: From<T>> From<&T> for U`), so this borrowed-
1359/// input axis is a distinct trait-idiomatic surface that the pipe shape
1360/// [`CaixaDialeto::ALL`]`.iter().map(std::sync::Arc::<str>::from)` reaches
1361/// through this impl and no other — without it, the same pipe would force
1362/// a spurious [`Copy`] deref
1363/// (`std::sync::Arc::<str>::from((*dialeto).as_str())`) or a `.copied()`
1364/// restatement whose type bounds have no compile-time link back to the
1365/// substrate primitive.
1366///
1367/// Closes the `{Self, &Self}` input-shape corner on the third caixa-core-
1368/// internal closed-set fieldless typed enum peer of the substrate-wide
1369/// trait-idiomatic [`std::sync::Arc<str>`] forward-projection campaign,
1370/// matching the trajectory the paired structurally most fundamental
1371/// [`crate::CaixaKind`] pair (c17be64, both corners in one axis) and the
1372/// paired outside-M3 caixa-core two-list dep-graph [`crate::dep::DepList`]
1373/// pair (d8a4652, both corners in one axis) walked before it on the
1374/// caixa-core-internal tier of the same axis. Same
1375/// `{Self, &Self} × {&'static str, String, Cow<'static, str>, Box<str>,
1376/// std::sync::Arc<str>}` 2×5 forward-projection matrix the peer projection
1377/// surfaces already close on this same enum.
1378///
1379/// Pinned load-bearing by
1380/// [`tests::caixa_dialeto_from_borrowed_into_arc_str_routes_through_as_str_accessor`]
1381/// (byte-parity pin against [`CaixaDialeto::as_str`] across the four-arm
1382/// [`CaixaDialeto::ALL`] emit-set on the borrowed-input surface, plus a
1383/// blanket-derived [`Into`] shape witness, a cross-axis partition pin
1384/// against the paired owned-input
1385/// [`From<CaixaDialeto> for std::sync::Arc<str>`] and the sibling borrowed-
1386/// input `{&'static str, String, Cow<'static, str>, Box<str>}` return-shape
1387/// axes, and a `.iter().map(std::sync::Arc::<str>::from)` pipe witness over
1388/// [`CaixaDialeto::ALL`] that resolves through the borrowed-input axis
1389/// without a spurious [`Copy`] deref).
1390impl From<&CaixaDialeto> for std::sync::Arc<str> {
1391 fn from(dialeto: &CaixaDialeto) -> std::sync::Arc<str> {
1392 std::sync::Arc::<str>::from(dialeto.as_str())
1393 }
1394}
1395
1396/// A source that is not a `(defcaixa …)` / `(defmolde …)` form at all.
1397#[derive(Debug, Clone, PartialEq, Eq, thiserror::Error)]
1398pub enum DialetoError {
1399 #[error("source has no top-level form")]
1400 Vazio,
1401 #[error("top-level form is not a list — a manifest is `(defcaixa …)`")]
1402 NaoEhLista,
1403 #[error(
1404 "top-level form is headed by `{encontrado}`, not `defcaixa` or `defmolde` \
1405 (a manifest's first form must be the declaration itself)"
1406 )]
1407 CabecaErrada { encontrado: String },
1408 #[error("manifest does not parse as tatara-lisp: {0}")]
1409 Leitura(String),
1410}
1411
1412impl DialetoError {
1413 /// Construct a [`DialetoError::CabecaErrada`] naming the offending
1414 /// head symbol found at the top-level form.
1415 ///
1416 /// Substrate primitive every [`classify_form`] wrong-head fallthrough
1417 /// wire-up site now routes through, folding the pre-lift uniform
1418 /// three-line `Self::CabecaErrada { encontrado: <head>.to_string() }`
1419 /// one-field struct-literal onto one substrate primitive matching the
1420 /// peer `LimitsError::unknown_byte_unit(unit: &str)` /
1421 /// `LimitsError::unknown_duration_unit(unit: &str)`
1422 /// (`limits_codec_unit_only_ctors!` — 29fac09) single-slot
1423 /// discipline on the sibling one-field `{ <field>: String }` envelope
1424 /// axis, and matching the peer `ManifestError::code_path_empty` /
1425 /// `BehaviorError::empty_path` / `UpgradeError::duplicate_from` /
1426 /// `AplicacaoError::placement_cluster_duplicate` (94dabc8 / 0e33b37 /
1427 /// 7e52aec / 92b1c92) single-slot inherent-ctor discipline every
1428 /// sibling `{ <field>: <T> }` error-envelope variant on caixa-core's
1429 /// error surface now carries.
1430 ///
1431 /// The one open-coded wire-up site — `classify_form`'s wrong-head
1432 /// fallthrough arm on the `head: &str` binding read from the
1433 /// top-level form via [`tatara_lisp::Sexp::as_symbol`] — opened the
1434 /// identical three-line
1435 /// `Self::CabecaErrada { encontrado: <head>.to_string() }` block
1436 /// against the codec-scoped `<head>: &str` binding. Now routes
1437 /// through `DialetoError::cabeca_errada(head)`, byte-equal to the
1438 /// pre-lift struct-literal on the same `&str` fixture, so any future
1439 /// widening of the diagnostic shape (e.g. carrying the source-file
1440 /// path alongside the head symbol, carrying the head symbol's
1441 /// position offset for an authoring-surface caret pointer) lands at
1442 /// exactly one dispatch on the substrate primitive rather than re-
1443 /// inlining the struct-literal at every wrong-head fallthrough
1444 /// consumer.
1445 #[must_use]
1446 pub fn cabeca_errada(encontrado: &str) -> Self {
1447 Self::CabecaErrada {
1448 encontrado: encontrado.to_string(),
1449 }
1450 }
1451
1452 /// Construct a [`DialetoError::Leitura`] carrying the offending
1453 /// tatara-lisp reader-error message `reason` verbatim in the
1454 /// variant's tuple-newtype payload.
1455 ///
1456 /// Substrate primitive every [`classify`] tatara-lisp-reader
1457 /// map-err wire-up site now routes through, folding the pre-lift
1458 /// uniform `Self::Leitura(<into-String-expr>)` tuple-newtype
1459 /// construction onto one substrate primitive matching the peer
1460 /// `LimitsError::empty_byte_size` / `LimitsError::empty_duration`
1461 /// (7a4b003 / 319216c) `(String)` single-slot tuple-newtype
1462 /// discipline on the sibling
1463 /// [`crate::limits::LimitsError`] envelope's empty-shape axis of
1464 /// the paired codec-magnitude family. Peer to the sibling
1465 /// [`DialetoError::cabeca_errada`] ctor on the same envelope's
1466 /// wrong-head axis but on the tatara-lisp-reader axis rather than
1467 /// the classifier-fallthrough axis. Closes the last un-lifted
1468 /// variant on [`DialetoError`] — every one of the sole wire-up
1469 /// sites (the [`classify`] tatara-lisp-reader `.map_err(|e|
1470 /// Self::Leitura(e.to_string()))` arm) opened the identical
1471 /// `DialetoError::Leitura(<into-String-expr>)` block against the
1472 /// codec-scoped `String` (`e.to_string()`) binding, so the fold
1473 /// routes the site through one dispatch on a uniform
1474 /// `impl Into<String>` param, byte-equal to the pre-lift
1475 /// tuple-newtype construction on the same argument.
1476 ///
1477 /// The `impl Into<String>` bound covers both wire-up shapes on
1478 /// [`classify`] — a `String` binding (`e.to_string()` on the
1479 /// [`tatara_lisp::Error`]-carrying `e` binding) and a `&str`
1480 /// binding (a future admission-webhook consumer probing a
1481 /// caller-scoped `&'static str` fixture, a future
1482 /// `feira lint --tatara-reader-round-trip` verb sweeping every
1483 /// `tatara_lisp::read` return through the same shape gate) —
1484 /// without forcing the caller to spell the conversion at the
1485 /// wire-up site. Same shape the peer
1486 /// [`crate::limits::LimitsError::empty_byte_size`] /
1487 /// [`crate::limits::LimitsError::empty_duration`] /
1488 /// [`crate::limits::LimitsError::bad_millicores`] /
1489 /// [`crate::limits::LimitsError::bad_byte_magnitude`] /
1490 /// [`crate::limits::LimitsError::bad_duration_magnitude`] folds
1491 /// carry on the peer bad-magnitude and empty-shape axes of the
1492 /// same paired `(String)` tuple-newtype codec-magnitude family.
1493 /// `#[must_use]` fires a compile warning at any wire-up that
1494 /// mistakenly discards the constructed error.
1495 ///
1496 /// Every future consumer that wants to construct this variant
1497 /// outside [`classify`] (a deferred `feira lint --tatara-reader-
1498 /// round-trip` per-caixa admission verb probing each authored
1499 /// manifest against the tatara-lisp-reader shape gate, an M4
1500 /// typed `mesh.pleme.io/v1alpha1/Servico` CR materializer's
1501 /// per-manifest admission validator re-checking one edited
1502 /// `caixa.lisp` against the reader floor, a per-`caixa.lisp`
1503 /// value-shape pre-emitter probing each declared manifest ahead
1504 /// of the operator's admit-cycle) now reaches the variant
1505 /// through one call rather than re-inlining the tuple-newtype
1506 /// block in lockstep with the pre-existing wire-up.
1507 #[must_use]
1508 pub fn leitura(reason: impl Into<String>) -> Self {
1509 Self::Leitura(reason.into())
1510 }
1511}
1512
1513/// Classify a manifest source without committing to either schema.
1514///
1515/// Deliberately reads only the head symbol and the set of top-level keywords —
1516/// enough to route, never enough to half-parse. A classifier that started
1517/// validating would grow into a third parser, which is the shape of the problem
1518/// it exists to name.
1519///
1520/// # Errors
1521/// [`DialetoError`] when the source is not a manifest declaration at all.
1522pub fn classify(src: &str) -> Result<CaixaDialeto, DialetoError> {
1523 let forms = tatara_lisp::read(src).map_err(|e| DialetoError::leitura(e.to_string()))?;
1524 let first = forms.first().ok_or(DialetoError::Vazio)?;
1525 classify_form(first)
1526}
1527
1528/// [`classify`] over an already-read form.
1529///
1530/// # Errors
1531/// [`DialetoError`] when the form is not a manifest declaration.
1532pub fn classify_form(form: &Sexp) -> Result<CaixaDialeto, DialetoError> {
1533 let list = form.as_list().ok_or(DialetoError::NaoEhLista)?;
1534 let head = list
1535 .first()
1536 .and_then(Sexp::as_symbol)
1537 .ok_or(DialetoError::NaoEhLista)?;
1538
1539 match head {
1540 // `defmolde` is unambiguous by construction — it exists precisely so a
1541 // consumer never has to infer which declaration it holds. Both arities
1542 // are the same declaration; the positional one keeps its own variant
1543 // only so a census can report the split.
1544 "defmolde" => {
1545 return Ok(if starts_with_positional_name(&list[1..]) {
1546 CaixaDialeto::MoldePosicional
1547 } else {
1548 CaixaDialeto::Molde
1549 });
1550 }
1551 "defcaixa" => {}
1552 other => {
1553 return Err(DialetoError::cabeca_errada(other));
1554 }
1555 }
1556
1557 let args = &list[1..];
1558
1559 // `(defcaixa <symbol> :kind … :ecosystem …)`. Only the Molde dialect has a
1560 // positional arity; `Caixa` is keyword-only, so a leading bare symbol
1561 // settles it without looking further.
1562 if starts_with_positional_name(args) {
1563 return Ok(CaixaDialeto::MoldePosicional);
1564 }
1565
1566 let keys = top_level_keywords(args);
1567 let has = |k: &str| keys.iter().any(|s| s == k);
1568
1569 // Order matters, and it is not arbitrary: `:nome` and `:name` are the two
1570 // required head slots and no file in the measured corpus carries both.
1571 // Checking them FIRST means the decision rests on the one slot each schema
1572 // makes mandatory, rather than on optional evidence like `:ecosystem`.
1573 if has("nome") {
1574 return Ok(CaixaDialeto::Pacote);
1575 }
1576 if has("name") || has("ecosystem") || has("package") {
1577 return Ok(CaixaDialeto::Molde);
1578 }
1579 Ok(CaixaDialeto::Desconhecido)
1580}
1581
1582/// True when the first argument is a bare symbol rather than a keyword — the
1583/// positional-name arity.
1584fn starts_with_positional_name(args: &[Sexp]) -> bool {
1585 matches!(args.first(), Some(Sexp::Atom(Atom::Symbol(_))))
1586}
1587
1588/// The top-level keyword names (without the leading `:`) of a kwarg list.
1589///
1590/// Steps in pairs so a keyword appearing as a VALUE — `:kind :Biblioteca`, or a
1591/// nested `(:nome "dep" :versao "^0.1")` inside `:deps` — is never counted as a
1592/// top-level slot. A naive scan for `:nome` anywhere in the source classifies
1593/// every Molde manifest with a `:deps` list as a Pacote.
1594fn top_level_keywords(args: &[Sexp]) -> Vec<String> {
1595 let mut out = Vec::new();
1596 let mut i = 0;
1597 while i < args.len() {
1598 if let Sexp::Atom(Atom::Keyword(k)) = &args[i] {
1599 out.push(k.clone());
1600 i += 2;
1601 } else {
1602 i += 1;
1603 }
1604 }
1605 out
1606}
1607
1608#[cfg(test)]
1609mod tests {
1610 use super::*;
1611
1612 const PACOTE: &str = r#"
1613 (defcaixa
1614 :nome "checkout"
1615 :versao "0.1.0"
1616 :kind Servico
1617 :deps ((:nome "caixa-teia" :versao "^0.1")))
1618 "#;
1619
1620 const MOLDE: &str = r#"
1621 (defcaixa
1622 :name "base64"
1623 :kind :Biblioteca
1624 :ecosystem :rust-single-crate
1625 :package {:name "base64" :version "0.22.1"}
1626 :workflows [:auto-release])
1627 "#;
1628
1629 const MOLDE_POSICIONAL: &str = r#"
1630 (defcaixa todoku-go
1631 :kind :Biblioteca
1632 :ecosystem :go
1633 :package {:name "todoku-go" :version "0.3.0"})
1634 "#;
1635
1636 #[test]
1637 fn the_package_dialect_is_recognised() {
1638 assert_eq!(classify(PACOTE), Ok(CaixaDialeto::Pacote));
1639 }
1640
1641 #[test]
1642 fn the_repo_surface_dialect_is_recognised() {
1643 assert_eq!(classify(MOLDE), Ok(CaixaDialeto::Molde));
1644 }
1645
1646 #[test]
1647 fn the_positional_arity_is_recognised() {
1648 assert_eq!(
1649 classify(MOLDE_POSICIONAL),
1650 Ok(CaixaDialeto::MoldePosicional)
1651 );
1652 }
1653
1654 #[test]
1655 fn defmolde_classifies_without_inference() {
1656 // The whole point of the new keyword: no schema sniffing required.
1657 let src = r#"(defmolde :name "x" :kind :Biblioteca :ecosystem :go)"#;
1658 assert_eq!(classify(src), Ok(CaixaDialeto::Molde));
1659 let pos = r"(defmolde todoku-go :kind :Biblioteca :ecosystem :go)";
1660 assert_eq!(classify(pos), Ok(CaixaDialeto::MoldePosicional));
1661 }
1662
1663 #[test]
1664 fn a_nested_nome_does_not_make_a_repo_surface_look_like_a_package() {
1665 // The exact failure a substring scan produces: `:deps ((:nome …))`
1666 // contains `:nome`, but not as a top-level slot.
1667 let src = r#"
1668 (defcaixa
1669 :name "x"
1670 :ecosystem :rust-single-crate
1671 :deps ((:nome "inner" :versao "^0.1")))
1672 "#;
1673 assert_eq!(classify(src), Ok(CaixaDialeto::Molde));
1674 }
1675
1676 #[test]
1677 fn a_keyword_in_value_position_is_not_a_slot() {
1678 // `:kind :Biblioteca` — the value is itself a keyword. Stepping one at
1679 // a time would read `:Biblioteca` as a top-level slot.
1680 let src = r#"(defcaixa :kind :Biblioteca :name "x")"#;
1681 assert_eq!(classify(src), Ok(CaixaDialeto::Molde));
1682 }
1683
1684 #[test]
1685 fn an_unrecognised_defcaixa_is_reported_not_guessed() {
1686 let src = r#"(defcaixa :licenca "MIT")"#;
1687 assert_eq!(classify(src), Ok(CaixaDialeto::Desconhecido));
1688 }
1689
1690 #[test]
1691 fn a_form_that_is_not_a_manifest_is_an_error_not_a_dialect() {
1692 assert_eq!(
1693 classify("(defflake :nome \"x\")"),
1694 Err(DialetoError::cabeca_errada("defflake"))
1695 );
1696 assert_eq!(classify(""), Err(DialetoError::Vazio));
1697 }
1698
1699 #[test]
1700 fn every_dialect_names_its_consumer_and_its_canonical_keyword() {
1701 // Guards the routing table itself: a new variant added without an arm
1702 // here is a compile error in the match, and a variant that claims
1703 // `defcaixa` while being read by pleme-doc-gen would re-open the
1704 // collision this module closes. Sweeps [`CaixaDialeto::ALL`] rather
1705 // than the pre-lift open-coded four-arm literal list — a future arm
1706 // addition extends the slice as one edit and this pin picks it up
1707 // by construction.
1708 for &d in CaixaDialeto::ALL {
1709 assert!(!d.descricao().is_empty(), "{d}");
1710 assert!(!d.consumidor().is_empty(), "{d}");
1711 }
1712 assert_eq!(CaixaDialeto::Pacote.palavra_canonica(), "defcaixa");
1713 assert_eq!(CaixaDialeto::Molde.palavra_canonica(), "defmolde");
1714 assert_ne!(
1715 CaixaDialeto::Pacote.palavra_canonica(),
1716 CaixaDialeto::Molde.palavra_canonica(),
1717 "the two dialects must not share a canonical keyword — that IS the defect"
1718 );
1719 }
1720
1721 #[test]
1722 fn caixa_dialeto_all_enumerates_every_variant_exactly_once() {
1723 // Three-legged exhaustiveness pin, peer of the sibling
1724 // `caixa_kind_all_enumerates_every_variant_exactly_once`
1725 // (caixa-core/src/kind.rs) /
1726 // `restart_strategy_all_enumerates_every_variant_exactly_once`
1727 // (caixa-core/src/supervisor.rs) shape.
1728 //
1729 // 1. arm-count invariant: `ALL.len()` matches the declared arm
1730 // count (four — a fifth arm added without extending `ALL`
1731 // fails this pin at caixa-core test time);
1732 // 2. pairwise-distinctness invariant: every variant appears at
1733 // most once in the slice (a duplicate arm would silently
1734 // double-count in the census consumer, so the pin rejects
1735 // duplicates outright);
1736 // 3. coverage invariant: every literal `CaixaDialeto::X` is in
1737 // the slice (the compiler-checked exhaustiveness on the peer
1738 // per-arm `match self` in the accessors keeps the enum arm
1739 // set and the `ALL` slice mutually aligned).
1740 assert_eq!(
1741 CaixaDialeto::ALL.len(),
1742 4,
1743 "ALL must list every arm exactly once; a fifth arm added \
1744 without extending ALL fails this pin — extend ALL alongside \
1745 the new variant"
1746 );
1747
1748 let mut seen: Vec<CaixaDialeto> = Vec::new();
1749 for &d in CaixaDialeto::ALL {
1750 assert!(
1751 !seen.contains(&d),
1752 "ALL contains a duplicate arm: {d}. Every variant appears \
1753 exactly once — a duplicate would double-count in every \
1754 iteration consumer"
1755 );
1756 seen.push(d);
1757 }
1758
1759 // Coverage: exhaustively assert every literal variant is somewhere
1760 // in the slice. Written as an exhaustive `match` so a future arm
1761 // addition fails to compile here (missing match arm) until the
1762 // corresponding `assert` is added — the compiler enforces the pin's
1763 // completeness rather than a hand-maintained variant list.
1764 for variant in [
1765 CaixaDialeto::Pacote,
1766 CaixaDialeto::Molde,
1767 CaixaDialeto::MoldePosicional,
1768 CaixaDialeto::Desconhecido,
1769 ] {
1770 let coverage_probe = match variant {
1771 CaixaDialeto::Pacote
1772 | CaixaDialeto::Molde
1773 | CaixaDialeto::MoldePosicional
1774 | CaixaDialeto::Desconhecido => variant,
1775 };
1776 assert!(
1777 CaixaDialeto::ALL.contains(&coverage_probe),
1778 "ALL is missing variant {coverage_probe} — extend the slice"
1779 );
1780 }
1781 }
1782
1783 #[test]
1784 fn caixa_dialeto_all_is_const_and_matches_iteration_count() {
1785 // Pins the const-ness of the slice at const-fold time. A future
1786 // change that promoted `ALL` to a non-const initializer (a lazy-
1787 // static, a runtime-computed Vec) would fail to compile here —
1788 // the pin locks in the compile-time-known iteration surface
1789 // every consumer builds against. Peer of the sibling
1790 // `caixa_kind_all_is_const_and_matches_iteration_count` (kind.rs)
1791 // / `restart_strategy_all_is_const_and_matches_iteration_count`
1792 // (supervisor.rs) shape.
1793 const ALL: &[CaixaDialeto] = CaixaDialeto::ALL;
1794 assert_eq!(ALL.len(), CaixaDialeto::ALL.len());
1795 // Sweep the iterator without collapsing to `.len()` so a future
1796 // change to `ALL`'s carrier that decouples `.len()` from the
1797 // iteration count (a lazy-computed shape, an alias `impl Iterator`
1798 // return, a wrapper newtype) still passes here iff the two agree
1799 // arm-for-arm; the `#[allow]` opts this local pin out of the
1800 // clippy `iter_count` collapse that would defeat the intent.
1801 #[allow(clippy::iter_count)]
1802 let iterated = ALL.iter().count();
1803 assert_eq!(iterated, CaixaDialeto::ALL.len());
1804 }
1805
1806 #[test]
1807 fn caixa_dialeto_all_covers_every_variant_by_display_probe() {
1808 // Fanning `Display` over the slice sweeps the paired accessors
1809 // ([`CaixaDialeto::palavra_canonica`] / [`CaixaDialeto::consumidor`]
1810 // / [`CaixaDialeto::descricao`]) at every arm — every returned
1811 // byte-string is non-empty (the accessors' contract). A future
1812 // arm added without extending its per-arm `match self` return
1813 // would compile-fail at the accessor call inside the loop;
1814 // together with the `ALL.len() == 4` pin above, this locks the
1815 // accessor arm-set and the `ALL` slice mutually.
1816 for &d in CaixaDialeto::ALL {
1817 let display_form = d.to_string();
1818 assert!(
1819 !display_form.is_empty(),
1820 "Display must render a non-empty byte-string for every \
1821 arm; empty: {d:?}"
1822 );
1823 // Consumidor / descricao / palavra-canonica must each surface
1824 // a non-empty scalar; every downstream diagnostic consumer
1825 // reaches through these accessors.
1826 assert!(!d.palavra_canonica().is_empty(), "{d}");
1827 assert!(!d.consumidor().is_empty(), "{d}");
1828 assert!(!d.descricao().is_empty(), "{d}");
1829 }
1830 }
1831
1832 #[test]
1833 fn caixa_dialeto_as_str_returns_pascal_case_variant_name() {
1834 // Fail-before-pass-after per-arm shape pin: the four
1835 // [`CaixaDialeto::as_str`] arms must return the canonical
1836 // `PascalCase` byte-string that names the variant. Pre-lift this
1837 // byte-string existed only inside the hand-rolled Display impl's
1838 // four-arm literal-string match — every consumer that wanted the
1839 // `PascalCase` name reached through `format!("{d}")`'s allocation
1840 // path. Pinning the four arms explicitly here refuses a future
1841 // regression that ever reroutes an arm to a distinct spelling
1842 // (`"pacote"` lowercase, `"MoldePositional"` English rebrand,
1843 // `"Unknown"` for `Desconhecido`) — the census output and the
1844 // typed accessor would silently disagree until a downstream
1845 // consumer surfaced the drift at census time. Peer of the sibling
1846 // [`crate::supervisor::tests::restart_strategy_variants_serialize_to_lifted_scalar_values`]
1847 // / `placement_strategy_variants_serialize_to_lifted_scalar_values`
1848 // / `caixa_kind_as_str_returns_lifted_peer_const` shape on the
1849 // sibling closed-set typed-enum discriminator axes — the seventh
1850 // (and last unlifted) closed-set typed enum on the caixa surface
1851 // to converge onto the same per-arm-shape-pin discipline.
1852 for (variant, expected) in [
1853 (CaixaDialeto::Pacote, "Pacote"),
1854 (CaixaDialeto::Molde, "Molde"),
1855 (CaixaDialeto::MoldePosicional, "MoldePosicional"),
1856 (CaixaDialeto::Desconhecido, "Desconhecido"),
1857 ] {
1858 assert_eq!(
1859 variant.as_str(),
1860 expected,
1861 "CaixaDialeto::{variant:?}.as_str() must return the \
1862 canonical `PascalCase` variant-name byte-string; drift here \
1863 splits the census-facing text from the substrate \
1864 primitive every downstream consumer will read"
1865 );
1866 }
1867 }
1868
1869 #[test]
1870 fn caixa_dialeto_display_routes_through_as_str_helper() {
1871 // Fail-before-pass-after convergence pin: for every arm in
1872 // [`CaixaDialeto::ALL`], the [`std::fmt::Display`] rendered form
1873 // must byte-equal [`CaixaDialeto::as_str`]'s return value. Pre-
1874 // lift these two paths were structurally independent — the
1875 // Display impl hand-rolled its own four-arm literal-string
1876 // match with no compile-time link back to any substrate accessor
1877 // — so a future variant rename could land at `Display` without
1878 // touching a paired accessor (or vice versa), silently splitting
1879 // the two paths on the renamed arm. Pinning the byte-equality
1880 // here makes any such split a caixa-core build-time failure at
1881 // this test rather than surfacing far from the rename commit as
1882 // a downstream census consumer emitting one spelling while the
1883 // typed accessor returned another. Peer of the sibling
1884 // [`crate::kind::tests::caixa_kind_display_routes_through_as_str_helper`]
1885 // (which pins the same convergence on the [`crate::CaixaKind`]
1886 // closed-set axis) — extends the discipline onto the seventh
1887 // (and last unlifted) closed-set fieldless typed enum on the
1888 // caixa surface.
1889 for &variant in CaixaDialeto::ALL {
1890 assert_eq!(
1891 variant.to_string(),
1892 variant.as_str(),
1893 "CaixaDialeto::{variant:?} Display must route through \
1894 CaixaDialeto::as_str (single source of truth: the \
1895 lifted per-arm `PascalCase` variant-name byte-string)"
1896 );
1897 }
1898 }
1899
1900 #[test]
1901 fn caixa_dialeto_as_ref_str_routes_through_as_str_accessor() {
1902 // Fail-before-pass-after byte-parity pin on the lifted
1903 // `impl AsRef<str> for CaixaDialeto` — asserts the standard-
1904 // library trait impl and the substrate-primitive
1905 // [`CaixaDialeto::as_str`] `pub const fn` accessor resolve to
1906 // the same `&str` per instance across the four-arm closed set,
1907 // so any future silent detour that routes the impl through a
1908 // divergent projection (a per-arm inline
1909 // `match self { CaixaDialeto::Pacote => "Pacote", … }` re-inlining
1910 // that opens a compile-time link to the un-lifted arm-literal,
1911 // a swap onto the second-axis
1912 // [`CaixaDialeto::palavra_canonica`] /
1913 // [`CaixaDialeto::consumidor`] / [`CaixaDialeto::descricao`]
1914 // accessors that carry distinct byte-shapes per axis) trips at
1915 // caixa-core test time under `PartialEq` rather than at a
1916 // downstream `impl AsRef<str>`-bound consumer's silent split.
1917 // Sweeps every one of the four arms [`CaixaDialeto::ALL`]
1918 // carries so no arm's projection is covered only by the sibling
1919 // `Display` path. Peer of the sibling
1920 // `rate_limit_unit_as_ref_str_routes_through_as_suffix_accessor`
1921 // (d8136db) on the M3 `:politicas :rate-limit` closed-set typed
1922 // enum, and the peer
1923 // [`crate::kind::tests::caixa_kind_as_ref_str_routes_through_as_str_accessor`]
1924 // (cd2091f) pin on the top-level closed-set typed
1925 // discriminator — the pins together close the substrate
1926 // primitive's `AsRef<str>` projection axis onto the seventh
1927 // closed-set fieldless typed enum on the caixa surface.
1928 for &variant in CaixaDialeto::ALL {
1929 assert_eq!(
1930 <CaixaDialeto as AsRef<str>>::as_ref(&variant),
1931 variant.as_str(),
1932 "AsRef<str> impl on CaixaDialeto::{variant:?} must \
1933 byte-equal CaixaDialeto::as_str on the same instance \
1934 — divergence signals a silent detour off the \
1935 substrate-primitive accessor"
1936 );
1937 }
1938 }
1939
1940 #[test]
1941 fn caixa_dialeto_as_ref_str_routes_through_display_via_shared_accessor() {
1942 // Fail-before-pass-after byte-parity pin on the three-path
1943 // convergence discipline the [`CaixaDialeto`] closed-set
1944 // dialect-classification enum now carries on the `&str`-
1945 // projection axis: `<CaixaDialeto as AsRef<str>>::as_ref(&v)`
1946 // (the newly lifted impl), `format!("{v}")` (the pre-existing
1947 // [`fmt::Display`] impl), and `v.as_str()` (the substrate-
1948 // primitive `pub const fn` accessor both trait impls delegate
1949 // through) must resolve to the same byte-string on every
1950 // instance across the four-arm closed set. Refuses any future
1951 // divergence between the two trait impls (a stray
1952 // [`fmt::Display::fmt`] rewrite that hand-rolls the arms
1953 // rather than delegating through the shared accessor; a
1954 // hypothetical `AsRef<str>` rewrite that inlines a per-arm
1955 // literal cascade) that would silently split the two
1956 // projection paths of the same closed-set typed enum. Mirrors
1957 // the sibling three-path-convergence discipline the peer
1958 // [`crate::aplicacao::RateLimitUnit`] typed enum carries
1959 // (`rate_limit_unit_as_ref_str_routes_through_display_via_shared_accessor`,
1960 // d8136db), the peer [`crate::CaixaKind`] triple
1961 // (`caixa_kind_as_ref_str_routes_through_display_via_shared_accessor`,
1962 // cd2091f), and the [`crate::CaixaVersion`] typed newtype
1963 // triple (`caixa_version_as_ref_str_routes_through_display_via_shared_accessor`,
1964 // 16d5c7e).
1965 for &variant in CaixaDialeto::ALL {
1966 let via_as_ref: &str = <CaixaDialeto as AsRef<str>>::as_ref(&variant);
1967 let via_display: String = format!("{variant}");
1968 let via_accessor: &str = variant.as_str();
1969 assert_eq!(via_as_ref, via_accessor);
1970 assert_eq!(via_display, via_accessor);
1971 assert_eq!(via_as_ref, via_display.as_str());
1972 }
1973 }
1974
1975 #[test]
1976 fn caixa_dialeto_is_molde_family_returns_true_on_molde_and_positional_arms() {
1977 // Fail-before-pass-after per-arm shape pin on the two `defmolde`
1978 // declaration-family arms: [`CaixaDialeto::is_molde_family`] must
1979 // return `true` for [`CaixaDialeto::Molde`] and
1980 // [`CaixaDialeto::MoldePosicional`] — the two-arity closure of
1981 // one declaration ([`CaixaDialeto::MoldePosicional`]'s docstring:
1982 // "same declaration as [`Self::Molde`], written with the package
1983 // name as a bare positional symbol … one arity of one
1984 // declaration, not a third schema"). A future accidental flip that
1985 // reversed a per-arm arm's return without touching the paired
1986 // false-arm pin would silently open the substrate primitive to
1987 // false-positive on either arm — the `feira dialeto` verb's
1988 // `--strict-palavra` gate would then silently accept
1989 // repo-surface declarations under `(defcaixa …)` on one arm and
1990 // reject them on the other. Pinning the two true arms explicitly
1991 // here refuses that split at caixa-core build time.
1992 assert!(
1993 CaixaDialeto::Molde.is_molde_family(),
1994 "CaixaDialeto::Molde.is_molde_family() must return true — \
1995 Molde is the primary `defmolde` arm"
1996 );
1997 assert!(
1998 CaixaDialeto::MoldePosicional.is_molde_family(),
1999 "CaixaDialeto::MoldePosicional.is_molde_family() must return \
2000 true — MoldePosicional is the positional-arity form of the \
2001 same `defmolde` declaration Molde carries"
2002 );
2003 }
2004
2005 #[test]
2006 fn caixa_dialeto_is_molde_family_returns_false_on_pacote_and_desconhecido_arms() {
2007 // Fail-before-pass-after per-arm shape pin on the two non-`defmolde`
2008 // arms: [`CaixaDialeto::is_molde_family`] must return `false` for
2009 // [`CaixaDialeto::Pacote`] (the sibling `defcaixa` tatara-lisp
2010 // package manifest, `palavra_canonica → "defcaixa"`) and for
2011 // [`CaixaDialeto::Desconhecido`] (the residue that names no
2012 // known declaration, `palavra_canonica → "?"`). Pinning the two
2013 // false arms explicitly here refuses a future accidental flip
2014 // that let the predicate widen to include either arm — the
2015 // `feira dialeto` verb's `--strict-palavra` gate would then
2016 // spuriously refuse every `(defcaixa …)` package manifest as if
2017 // it were a repo-surface declaration.
2018 assert!(
2019 !CaixaDialeto::Pacote.is_molde_family(),
2020 "CaixaDialeto::Pacote.is_molde_family() must return false — \
2021 Pacote is the `defcaixa` tatara-lisp package manifest, not \
2022 the `defmolde` repo-surface declaration"
2023 );
2024 assert!(
2025 !CaixaDialeto::Desconhecido.is_molde_family(),
2026 "CaixaDialeto::Desconhecido.is_molde_family() must return \
2027 false — the residue arm names no known declaration; it is \
2028 not silently promoted into the `defmolde` family"
2029 );
2030 }
2031
2032 #[test]
2033 fn caixa_dialeto_is_molde_family_agrees_with_palavra_canonica_defmolde_projection() {
2034 // Load-bearing pin: for every arm in [`CaixaDialeto::ALL`], the
2035 // typed [`CaixaDialeto::is_molde_family`] predicate must agree
2036 // byte-for-byte with the paired [`CaixaDialeto::palavra_canonica`]
2037 // projection's `== "defmolde"` classifier — i.e. the two paths
2038 // partition the four-arm discriminator set into the same
2039 // `{Molde, MoldePosicional}` and `{Pacote, Desconhecido}` halves.
2040 // Pre-lift the sibling [`CaixaDialeto::palavra_canonica`] projection
2041 // (which returns `"defmolde"` for `Molde | MoldePosicional`,
2042 // `"defcaixa"` for `Pacote`, `"?"` for `Desconhecido`) was the
2043 // only substrate-side surface carrying the two-arm collapse; the
2044 // hand-rolled `matches!(d, CaixaDialeto::Molde |
2045 // CaixaDialeto::MoldePosicional)` sites in the `feira dialeto`
2046 // verb expressed no compile-time link back to it. A future arm
2047 // addition — the module doc's "third dialect" hazard actualises
2048 // as a fifth arm belonging to the `defmolde` family — would land
2049 // one match arm at [`Self::palavra_canonica`]'s `defmolde` return
2050 // (extending the sibling projection) but silently split the
2051 // hand-rolled two-arm `matches!` predicate sites if the new arm's
2052 // `is_molde_family` return were forgotten. Pinning byte-equality
2053 // between the two paths here makes any such split a caixa-core
2054 // build-time failure at this test rather than surfacing far from
2055 // the arm-addition commit as a downstream `--strict-palavra` /
2056 // `caixa.lisp`-holds-wrong-declaration gate silently ignoring the
2057 // new arm.
2058 for &d in CaixaDialeto::ALL {
2059 let via_palavra_canonica = d.palavra_canonica() == "defmolde";
2060 let via_is_molde_family = d.is_molde_family();
2061 assert_eq!(
2062 via_is_molde_family, via_palavra_canonica,
2063 "CaixaDialeto::{d:?}.is_molde_family() ({via_is_molde_family}) \
2064 must agree with CaixaDialeto::{d:?}.palavra_canonica() == \
2065 \"defmolde\" ({via_palavra_canonica}) — a split between the \
2066 typed predicate and the sibling keyword projection would let \
2067 a future arm addition land at one path and drift at the other, \
2068 which is exactly the drift this pin refuses"
2069 );
2070 }
2071 }
2072
2073 #[test]
2074 fn caixa_dialeto_is_molde_family_is_const_fn() {
2075 // Const-context pin: [`CaixaDialeto::is_molde_family`] must remain
2076 // `const fn` (its match is a fieldless-arm literal-pattern
2077 // discriminator, so no non-const operation exists on the resolution
2078 // path). Downstream consumers reaching for the predicate from a
2079 // `const` context (a future substrate-wide const-fold-driven audit
2080 // table that materializes per-arm gate-membership at build time,
2081 // a per-arm CR-admission-webhook gate registration in a `const`
2082 // context) rely on the const-ness. A future accidental downgrade
2083 // to non-`const` (an added runtime helper reachable only from a
2084 // non-`const` context) trips at caixa-core build time rather than
2085 // surfacing as a downstream `const`-context regression far from
2086 // the predicate declaration. Peer of the sibling
2087 // [`caixa_dialeto_as_str_is_const_fn`] pin on the paired
2088 // [`CaixaDialeto::as_str`] byte-string axis.
2089 const ARMS: [(CaixaDialeto, bool); 4] = [
2090 (CaixaDialeto::Pacote, CaixaDialeto::Pacote.is_molde_family()),
2091 (CaixaDialeto::Molde, CaixaDialeto::Molde.is_molde_family()),
2092 (
2093 CaixaDialeto::MoldePosicional,
2094 CaixaDialeto::MoldePosicional.is_molde_family(),
2095 ),
2096 (
2097 CaixaDialeto::Desconhecido,
2098 CaixaDialeto::Desconhecido.is_molde_family(),
2099 ),
2100 ];
2101 // Materialize the const-fold-evaluated table into a runtime slice
2102 // assertion — carries the same `bool = const fn call` shape a raw
2103 // `assert!(const_bool)` would, without tripping the
2104 // `assertions_on_constants` clippy lint that a per-arm
2105 // `assert!(CONST)` on a `const bool` triggers when the arm-count
2106 // is enumerated flat rather than compared as a whole-table shape.
2107 assert_eq!(
2108 ARMS,
2109 [
2110 (CaixaDialeto::Pacote, false),
2111 (CaixaDialeto::Molde, true),
2112 (CaixaDialeto::MoldePosicional, true),
2113 (CaixaDialeto::Desconhecido, false),
2114 ],
2115 "CaixaDialeto::is_molde_family() must evaluate in const context \
2116 for every arm and land on the {{false, true, true, false}} \
2117 partition — a future accidental downgrade to non-`const` \
2118 would trip the const-context array-initializer here"
2119 );
2120 }
2121
2122 #[test]
2123 fn caixa_dialeto_as_str_is_const_fn() {
2124 // Const-context pin: [`CaixaDialeto::as_str`] must remain
2125 // `const fn` (its match arms return `pub const` byte-strings, so
2126 // no non-const operation exists on the resolution path).
2127 // Downstream consumers reaching for the accessor from a `const`
2128 // context (a future substrate-wide const-fold-driven audit table
2129 // that materializes every dialect's census label at build time,
2130 // a per-arm CR-admission-webhook message registration in a
2131 // `const` gate) rely on the const-ness. A future accidental
2132 // downgrade to non-`const` (an added runtime helper reachable
2133 // only from a non-`const` context, a manual hand-rolled `impl`
2134 // that shadows this method) trips at caixa-core build time
2135 // rather than surfacing as a downstream `const`-context
2136 // regression far from the accessor declaration. Peer of the
2137 // sibling [`crate::kind::tests::caixa_kind_wire_name_is_const_fn`]
2138 // pin on the paired [`crate::CaixaKind`] byte-string axis.
2139 const PACOTE: &str = CaixaDialeto::Pacote.as_str();
2140 const MOLDE: &str = CaixaDialeto::Molde.as_str();
2141 const MOLDE_POSICIONAL: &str = CaixaDialeto::MoldePosicional.as_str();
2142 const DESCONHECIDO: &str = CaixaDialeto::Desconhecido.as_str();
2143 assert_eq!(PACOTE, "Pacote");
2144 assert_eq!(MOLDE, "Molde");
2145 assert_eq!(MOLDE_POSICIONAL, "MoldePosicional");
2146 assert_eq!(DESCONHECIDO, "Desconhecido");
2147 }
2148
2149 #[test]
2150 fn caixa_dialeto_is_variant_predicates_partition_the_arm_set() {
2151 // Fail-before-pass-after pin on the [`gen_platform::IsVariant`]
2152 // derive: for each of the four variants at [`CaixaDialeto::ALL`]`[idx]`
2153 // the observed four-slot predicate row must equal a one-hot row
2154 // with the `true` at exactly `idx`. Pre-derive the closed four-arm
2155 // dialect-classification partition lived only inside the paired
2156 // per-arm projections' four-arm match resolvers ([`Self::as_str`] /
2157 // [`Self::palavra_canonica`] / [`Self::consumidor`] /
2158 // [`Self::descricao`]) plus the two-arm [`Self::is_molde_family`]
2159 // hand-rolled `matches!` (now routed through the derived
2160 // predicates); a future rebrand (an accidental
2161 // `#[is_variant(name = "…")]` drift, a manual hand-rolled `impl`
2162 // that shadows the derive-generated method, an arm rename that
2163 // reroutes one arm through the wrong predicate lane) trips this
2164 // pin at caixa-core build time rather than surfacing far from the
2165 // derive declaration as a downstream [`Self::is_molde_family`]
2166 // consumer accepting the wrong arm-set. The expected row is
2167 // generated live from the [`Self::ALL`] declaration order rather
2168 // than transcribed by hand so a copy-paste flip reroutes at the
2169 // identity-diagonal assertion.
2170 //
2171 // Peer of the sibling
2172 // [`crate::kind::tests::caixa_kind_is_variant_predicates_partition_the_arm_set`]
2173 // / [`crate::supervisor::tests::restart_strategy_is_variant_predicates_partition_the_arm_set`]
2174 // / [`crate::aplicacao::tests::placement_strategy_is_variant_predicates_partition_the_arm_set`]
2175 // / [`crate::upgrade::tests::upgrade_instruction_is_variant_predicates_partition_the_arm_set`]
2176 // pins on the sibling closed-set typed-enum discriminator axes.
2177 for (idx, &variant) in CaixaDialeto::ALL.iter().enumerate() {
2178 let observed = [
2179 variant.is_pacote(),
2180 variant.is_molde(),
2181 variant.is_molde_posicional(),
2182 variant.is_desconhecido(),
2183 ];
2184 let mut expected = [false; 4];
2185 expected[idx] = true;
2186 assert_eq!(
2187 observed, expected,
2188 "CaixaDialeto::{variant:?} at ALL[{idx}] is_* predicates \
2189 must fire only on their own arm lane (identity diagonal); \
2190 got {observed:?}",
2191 );
2192 }
2193 }
2194
2195 #[test]
2196 fn caixa_dialeto_is_variant_predicates_are_const_fn() {
2197 // The [`gen_platform::IsVariant`] derive emits `const fn`
2198 // predicates on the peer [`crate::CaixaKind`] +
2199 // [`crate::upgrade::UpgradeInstruction`] +
2200 // [`crate::supervisor::RestartStrategy`] +
2201 // [`crate::supervisor::RestartPolicy`] +
2202 // [`crate::aplicacao::PlacementStrategy`] +
2203 // [`crate::aplicacao::RateLimitUnit`] +
2204 // [`crate::dep::DepList`] closed-set typed enums — pin the same
2205 // posture on [`CaixaDialeto`] so a future accidental downgrade
2206 // to non-`const` (an added runtime helper reachable only from a
2207 // non-`const` context, a manual hand-rolled `impl` that shadows
2208 // the derive-generated method) trips at caixa-core build time
2209 // rather than surfacing as a downstream `const`-context
2210 // regression far from the derive declaration.
2211 // Use `const { assert!(…) }` (peer of the sibling
2212 // [`crate::render::PathShapeViolation`] +
2213 // [`crate::aplicacao::RateLimitUnit`] +
2214 // [`caixa_theme::style::Semantic`] const-fn pins) so the
2215 // const-context evaluation trips at const-fold time without
2216 // opening a per-`const bool` `assertions_on_constants` clippy
2217 // debt row this crate does not carry today for `dialeto.rs`.
2218 const { assert!(CaixaDialeto::Pacote.is_pacote()) };
2219 const { assert!(CaixaDialeto::Molde.is_molde()) };
2220 const { assert!(CaixaDialeto::MoldePosicional.is_molde_posicional()) };
2221 const { assert!(CaixaDialeto::Desconhecido.is_desconhecido()) };
2222 }
2223
2224 #[test]
2225 fn caixa_dialeto_from_wire_accepts_every_as_str_output() {
2226 // Fail-before-pass-after per-arm accept pin on the newly lifted
2227 // [`CaixaDialeto::from_wire`] reverse projection: every arm in
2228 // [`CaixaDialeto::ALL`] must parse back through `from_wire` when
2229 // fed its own [`CaixaDialeto::as_str`] output, landing on
2230 // `Some(same_variant)` — a regression that hand-rolled either
2231 // side's per-arm match without threading through the shared
2232 // four-string closed set would silently disagree on any future
2233 // arm rename and this pin flags it at caixa-core build time.
2234 // Peer of the sibling
2235 // [`crate::kind::tests::caixa_kind_wire_round_trips_through_from_wire`]
2236 // (2aa6d23) /
2237 // `placement_strategy_from_wire_accepts_every_lifted_constant`
2238 // (18c7342) /
2239 // `dep_list_round_trips_through_as_str_and_from_wire` (45ee563)
2240 // shape on the sibling closed-set typed-enum reverse-projection
2241 // axes.
2242 for &variant in CaixaDialeto::ALL {
2243 let wire = variant.as_str();
2244 let parsed = CaixaDialeto::from_wire(wire).unwrap_or_else(|| {
2245 panic!(
2246 "CaixaDialeto::from_wire({wire:?}) must accept every \
2247 CaixaDialeto::as_str output — got None for the \
2248 wire byte-string of {variant:?}"
2249 )
2250 });
2251 assert_eq!(
2252 parsed, variant,
2253 "CaixaDialeto::from_wire(CaixaDialeto::{variant:?}.as_str()) \
2254 must return CaixaDialeto::{variant:?} — the (as_str, \
2255 from_wire) pair must form a total round-trip on the \
2256 closed four-arm CaixaDialeto arm-set"
2257 );
2258 }
2259 }
2260
2261 #[test]
2262 fn caixa_dialeto_from_wire_rejects_unknown_byte_strings() {
2263 // Rejection pin on the parser's accept-set: any string outside
2264 // the four-arm [`CaixaDialeto::as_str`] output set must return
2265 // `None`. A future accidental widening of the accept-set (a
2266 // case-insensitive match that accepts `"pacote"` on the wire
2267 // axis, a hand-rolled Levenshtein-forgiving arm-lookup that
2268 // admits `"Pacotee"` typos, a silent acceptance of the sibling
2269 // [`Self::palavra_canonica`] `"defcaixa"` / `"defmolde"`
2270 // byte-shapes on this axis) would silently drift the parser's
2271 // accept-set from the emitter's — a downstream audit-report
2272 // re-loader that bound a prior audit's [`Self::as_str`] output
2273 // back to the typed enum through this parser would then bind a
2274 // malformed byte-string to a plausibly-wrong typed arm the
2275 // caller does not route through any fallback, silently
2276 // misclassifying the reloaded row. Also rejects the sibling
2277 // [`Self::palavra_canonica`] (`"defcaixa"` / `"defmolde"`) and
2278 // the sibling [`Self::consumidor`] (`"caixa-core / feira"`,
2279 // `"pleme-doc-gen"`, `"nobody known"`) byte-shapes, which are
2280 // the substrate's *distinct-axis* projections on the same enum
2281 // — the two-axis split the sibling
2282 // [`Self::palavra_canonica`] / [`Self::consumidor`] /
2283 // [`Self::descricao`] docstrings explicitly frame forbids
2284 // accepting one axis's byte-shapes as parseable on the other
2285 // axis. Peer of the sibling
2286 // [`crate::kind::tests::caixa_kind_from_wire_rejects_unknown_byte_strings`]
2287 // (2aa6d23) /
2288 // `placement_strategy_from_wire_rejects_unknown_byte_strings`
2289 // (18c7342) /
2290 // `dep_list_from_wire_returns_none_on_unknown_wire_scalar`
2291 // (45ee563) rejection pins on the sibling closed-set typed-enum
2292 // reverse-projection axes.
2293 for bad in [
2294 "",
2295 " ",
2296 "pacote",
2297 "PACOTE",
2298 "molde",
2299 "MoldePositional",
2300 "desconhecido",
2301 "Unknown",
2302 "defcaixa",
2303 "defmolde",
2304 "?",
2305 "caixa-core / feira",
2306 "pleme-doc-gen",
2307 "nobody known",
2308 "Pacote ",
2309 " Pacote",
2310 ] {
2311 assert!(
2312 CaixaDialeto::from_wire(bad).is_none(),
2313 "CaixaDialeto::from_wire({bad:?}) must return None — the \
2314 parser's accept-set is exactly the four CaixaDialeto::as_str \
2315 outputs; a widening would silently split the parser's \
2316 accept-set from the emitter's arm-set"
2317 );
2318 }
2319 }
2320
2321 #[test]
2322 fn cabeca_errada_ctor_matches_struct_literal_wrap() {
2323 // Fail-before-pass-after byte-identity pin: the lifted
2324 // [`DialetoError::cabeca_errada`] ctor MUST land on the exact
2325 // same struct-literal shape the pre-lift open-coded wire-up
2326 // block wrote by hand — `DialetoError::CabecaErrada {
2327 // encontrado: <head>.to_string() }`. A future accidental
2328 // divergence (`.into()` swap, per-arm constant substitution, an
2329 // added default field, an `.to_ascii_lowercase()` normalization
2330 // silently injected into the ctor body, a rebrand of the
2331 // `encontrado` field carrying a distinct byte-shape) trips this
2332 // pin at caixa-core build time rather than surfacing far from
2333 // the ctor declaration as a downstream `classify_form`
2334 // wrong-head consumer emitting one diagnostic shape while a
2335 // hand-written test peer opens another. Peer of the sibling
2336 // `unknown_byte_unit_ctor_matches_struct_literal_wrap`
2337 // (limits.rs; 29fac09) / `duplicate_from_ctor_matches_struct_
2338 // literal_wrap` (upgrade.rs; 7e52aec) shape on the sibling
2339 // single-slot `{ <field>: String }` envelope constructors.
2340 assert_eq!(
2341 DialetoError::cabeca_errada("defflake"),
2342 DialetoError::CabecaErrada {
2343 encontrado: "defflake".to_string(),
2344 },
2345 "DialetoError::cabeca_errada must byte-equal the pre-lift \
2346 open-coded struct-literal — a drift here means the ctor \
2347 stopped being a substrate primitive for the wrong-head \
2348 fallthrough site"
2349 );
2350 }
2351
2352 #[test]
2353 fn cabeca_errada_routes_encontrado_verbatim_across_boundary_inputs() {
2354 // Fail-before-pass-after boundary-sweep pin: the lifted
2355 // [`DialetoError::cabeca_errada`] ctor MUST route its
2356 // `encontrado: &str` argument verbatim into the
2357 // [`DialetoError::CabecaErrada`] `encontrado: String` field
2358 // for every boundary-covering `&str` input — empty string, a
2359 // canonical `defcaixa`-adjacent head, a non-ASCII head, a
2360 // whitespace-carrying head, a Unicode-full-width head. Any
2361 // wrapper-side truncation, silent `.trim()`, accidental
2362 // `.to_ascii_lowercase()` normalization, or `.into()` divergence
2363 // on the ctor body surfaces here as a byte-mismatch against the
2364 // input rather than at a downstream
2365 // [`DialetoError::to_string()`] diagnostic-shape drift at a
2366 // wrong-head fallthrough consumer far from the ctor declaration.
2367 // Peer of the sibling `limits_codec_unit_only_ctors_route_unit_
2368 // verbatim_across_every_variant` (limits.rs; 29fac09) shape on
2369 // the sibling single-slot `{ <field>: String }` envelope
2370 // boundary-sweep discipline.
2371 for encontrado in [
2372 "",
2373 "defflake",
2374 "def-molde",
2375 "defcaixa ",
2376 " defcaixa",
2377 "μdefcaixa",
2378 "\u{00A0}defcaixa",
2379 "\u{3000}defcaixa",
2380 "def\u{2028}caixa",
2381 ] {
2382 let via_ctor = DialetoError::cabeca_errada(encontrado);
2383 let via_literal = DialetoError::CabecaErrada {
2384 encontrado: encontrado.to_string(),
2385 };
2386 assert_eq!(
2387 via_ctor, via_literal,
2388 "DialetoError::cabeca_errada({encontrado:?}) must byte- \
2389 equal the open-coded struct-literal on the same input — \
2390 a drift here would let the ctor silently normalize / \
2391 truncate the head symbol before it reached the \
2392 CabecaErrada envelope"
2393 );
2394 let DialetoError::CabecaErrada { encontrado: routed } = via_ctor else {
2395 panic!(
2396 "DialetoError::cabeca_errada must construct the \
2397 CabecaErrada arm — got a different variant on \
2398 input {encontrado:?}"
2399 );
2400 };
2401 assert_eq!(
2402 routed, encontrado,
2403 "DialetoError::cabeca_errada must route the input \
2404 {encontrado:?} verbatim into the encontrado field — \
2405 any wrapper-side truncation / normalization surfaces \
2406 here rather than at a downstream diagnostic shape drift"
2407 );
2408 }
2409 }
2410
2411 #[test]
2412 fn classify_form_wrong_head_routes_through_cabeca_errada_ctor() {
2413 // Fail-before-pass-after routing pin: [`classify`]'s wrong-head
2414 // fallthrough site MUST construct its `Err(DialetoError::…)`
2415 // through the substrate-primitive [`DialetoError::cabeca_errada`]
2416 // ctor rather than through an open-coded struct-literal. Pre-
2417 // lift the wire-up hand-rolled a three-line
2418 // `Self::CabecaErrada { encontrado: other.to_string() }` block
2419 // with no compile-time link back to the substrate primitive; a
2420 // future accidental rebrand of the ctor body (an added
2421 // `.trim()` on `encontrado`, a per-arm constant prefix like
2422 // `"unknown-head:"`, a widening of the field into a
2423 // `(String, usize)` tuple carrying a caret offset) would then
2424 // silently split the two paths — the ctor consumers pick up
2425 // the new shape, the open-coded wire-up does not. Pinning
2426 // byte-equality between the observed `Err` and the ctor-
2427 // constructed `Err` refuses that split at caixa-core build
2428 // time rather than surfacing far from the wire-up commit as a
2429 // downstream diagnostic-consumer split.
2430 for head in ["defflake", "deffoobar", "defcaixaz", "let", "defmoldez"] {
2431 let src = format!("({head} :nome \"x\")");
2432 let observed = classify(&src);
2433 let via_ctor = Err(DialetoError::cabeca_errada(head));
2434 assert_eq!(
2435 observed, via_ctor,
2436 "classify({src:?}) must return the same Err shape as \
2437 DialetoError::cabeca_errada({head:?}) — a drift here \
2438 means the wire-up de-lifted its wrong-head fallthrough \
2439 arm off the substrate primitive"
2440 );
2441 }
2442 }
2443
2444 #[test]
2445 fn leitura_ctor_matches_tuple_literal_wrap_on_str_binding() {
2446 // Fail-before-pass-after byte-identity pin: the lifted
2447 // [`DialetoError::leitura`] ctor MUST land on the exact same
2448 // tuple-newtype wrap the pre-lift open-coded wire-up block wrote by
2449 // hand — `DialetoError::Leitura(<into-String-expr>)`. A future
2450 // accidental divergence (an added `.trim()` on the reader reason,
2451 // a per-arm constant prefix like `"tatara-lisp:"`, a widening of
2452 // the tuple carrying a caret offset, a rebrand of the payload
2453 // carrying a distinct byte-shape) trips this pin at caixa-core
2454 // build time rather than surfacing far from the ctor declaration
2455 // as a downstream [`classify`] tatara-lisp-reader consumer
2456 // emitting one diagnostic shape while a hand-written test peer
2457 // opens another. Peer of the sibling
2458 // `cabeca_errada_ctor_matches_struct_literal_wrap` pin above on
2459 // the same [`DialetoError`] envelope's wrong-head axis, and of
2460 // the peer `LimitsError::empty_byte_size` /
2461 // `LimitsError::empty_duration` (7a4b003 / 319216c) shape on the
2462 // sibling `(String)` single-slot tuple-newtype envelope
2463 // constructors.
2464 let reason: &str = "unclosed paren at 1:12";
2465 assert_eq!(
2466 DialetoError::leitura(reason),
2467 DialetoError::Leitura(reason.to_string()),
2468 "DialetoError::leitura must byte-equal the pre-lift open-coded \
2469 tuple-newtype wrap — a drift here means the ctor stopped \
2470 being a substrate primitive for the tatara-lisp-reader \
2471 fallthrough site"
2472 );
2473 }
2474
2475 #[test]
2476 fn leitura_ctor_matches_tuple_literal_wrap_on_string_binding() {
2477 // Fail-before-pass-after byte-identity pin on the `String` wire-up
2478 // shape: the lifted [`DialetoError::leitura`] ctor MUST land on
2479 // the same tuple-newtype wrap when the caller passes an owned
2480 // `String` (the actual [`classify`] wire-up shape — `e.to_string()`
2481 // on a [`tatara_lisp::Error`]-carrying binding). Pins that the
2482 // `impl Into<String>` param covers the owned-`String` path with no
2483 // silent double-allocation or intermediate `&str` reslicing. Peer
2484 // of the sibling `_on_str_binding` pin above — together they close
2485 // the `impl Into<String>` bound's two authored wire-up shapes on
2486 // the ctor's substrate primitive.
2487 let reason: String = String::from("read: unexpected EOF at 3:1");
2488 let via_ctor = DialetoError::leitura(reason.clone());
2489 let via_literal = DialetoError::Leitura(reason.clone());
2490 assert_eq!(
2491 via_ctor, via_literal,
2492 "DialetoError::leitura must byte-equal the pre-lift open-coded \
2493 tuple-newtype wrap on the same owned-String fixture — a drift \
2494 here would let the ctor silently reshape the reader reason \
2495 before it reached the Leitura envelope"
2496 );
2497 let DialetoError::Leitura(routed) = via_ctor else {
2498 panic!(
2499 "DialetoError::leitura must construct the Leitura arm — \
2500 got a different variant on input {reason:?}"
2501 );
2502 };
2503 assert_eq!(
2504 routed, reason,
2505 "DialetoError::leitura must route the input {reason:?} \
2506 verbatim into the tuple-newtype payload — any wrapper-side \
2507 truncation / normalization surfaces here rather than at a \
2508 downstream diagnostic shape drift"
2509 );
2510 }
2511
2512 #[test]
2513 fn leitura_routes_reason_verbatim_across_boundary_inputs() {
2514 // Fail-before-pass-after boundary-sweep pin: the lifted
2515 // [`DialetoError::leitura`] ctor MUST route its
2516 // `reason: impl Into<String>` argument verbatim into the
2517 // [`DialetoError::Leitura`] tuple-newtype `String` payload for
2518 // every boundary-covering input — empty string, a canonical
2519 // tatara-lisp reader error, a non-ASCII reason, a
2520 // whitespace-carrying reason, a Unicode-full-width reason. Any
2521 // wrapper-side truncation, silent `.trim()`, accidental
2522 // `.to_ascii_lowercase()` normalization, or `.into()` divergence
2523 // on the ctor body surfaces here as a byte-mismatch against the
2524 // input rather than at a downstream [`DialetoError::to_string()`]
2525 // diagnostic-shape drift at a tatara-lisp-reader fallthrough
2526 // consumer far from the ctor declaration. Peer of the sibling
2527 // `cabeca_errada_routes_encontrado_verbatim_across_boundary_inputs`
2528 // pin above on the same [`DialetoError`] envelope's wrong-head
2529 // axis.
2530 for reason in [
2531 "",
2532 "unclosed paren at 1:12",
2533 "unexpected token ')'",
2534 "read: eof",
2535 " leading whitespace",
2536 "trailing whitespace ",
2537 "μnicode reason",
2538 "\u{00A0}NBSP-prefixed reason",
2539 "\u{3000}ideographic-space reason",
2540 "reason\u{2028}with-line-separator",
2541 ] {
2542 let via_ctor = DialetoError::leitura(reason);
2543 let via_literal = DialetoError::Leitura(reason.to_string());
2544 assert_eq!(
2545 via_ctor, via_literal,
2546 "DialetoError::leitura({reason:?}) must byte-equal the \
2547 open-coded tuple-newtype wrap on the same input — a \
2548 drift here would let the ctor silently normalize / \
2549 truncate the reader reason before it reached the \
2550 Leitura envelope"
2551 );
2552 let DialetoError::Leitura(routed) = via_ctor else {
2553 panic!(
2554 "DialetoError::leitura must construct the Leitura \
2555 arm — got a different variant on input {reason:?}"
2556 );
2557 };
2558 assert_eq!(
2559 routed, reason,
2560 "DialetoError::leitura must route the input {reason:?} \
2561 verbatim into the tuple-newtype payload — any \
2562 wrapper-side truncation / normalization surfaces here \
2563 rather than at a downstream diagnostic shape drift"
2564 );
2565 }
2566 }
2567
2568 #[test]
2569 fn classify_reader_error_routes_through_leitura_ctor() {
2570 // Fail-before-pass-after routing pin: [`classify`]'s
2571 // tatara-lisp-reader map-err site MUST construct its
2572 // `Err(DialetoError::…)` through the substrate-primitive
2573 // [`DialetoError::leitura`] ctor rather than through an
2574 // open-coded tuple-newtype wrap. Pre-lift the wire-up hand-rolled
2575 // a `Self::Leitura(e.to_string())` block with no compile-time
2576 // link back to the substrate primitive; a future accidental
2577 // rebrand of the ctor body (an added `.trim()` on the reader
2578 // reason, a per-arm constant prefix like `"tatara-lisp:"`, a
2579 // widening of the payload into a `(String, usize)` tuple
2580 // carrying a caret offset) would then silently split the two
2581 // paths — the ctor consumers pick up the new shape, the
2582 // open-coded wire-up does not. Pinning byte-equality between
2583 // the observed `Err` and the ctor-constructed `Err` refuses
2584 // that split at caixa-core build time rather than surfacing far
2585 // from the wire-up commit as a downstream diagnostic-consumer
2586 // split. Peer of the sibling
2587 // `classify_form_wrong_head_routes_through_cabeca_errada_ctor`
2588 // pin above on the same [`DialetoError`] envelope's wrong-head
2589 // fallthrough axis.
2590 //
2591 // The malformed sources below each name a distinct
2592 // tatara-lisp-reader failure shape (unclosed paren, stray close
2593 // paren, unterminated string), so together they sweep the
2594 // reader's rejection surface rather than pinning against one
2595 // specific error message the reader upstream is free to reword.
2596 for src in [
2597 "(defcaixa :nome \"x\"",
2598 "defcaixa :nome \"x\")",
2599 "(defcaixa :nome \"unterminated",
2600 ] {
2601 let observed = classify(src);
2602 let Err(DialetoError::Leitura(reason)) = observed.clone() else {
2603 panic!(
2604 "classify({src:?}) must return the Leitura arm — got \
2605 {observed:?}"
2606 );
2607 };
2608 let via_ctor: Result<CaixaDialeto, DialetoError> =
2609 Err(DialetoError::leitura(reason.clone()));
2610 assert_eq!(
2611 observed, via_ctor,
2612 "classify({src:?}) must return the same Err shape as \
2613 DialetoError::leitura({reason:?}) — a drift here means \
2614 the wire-up de-lifted its tatara-lisp-reader fallthrough \
2615 arm off the substrate primitive"
2616 );
2617 }
2618 }
2619
2620 #[test]
2621 fn caixa_dialeto_try_from_str_routes_through_from_wire_accessor() {
2622 // Fail-before-pass-after byte-parity pin on the lifted
2623 // `impl TryFrom<&str> for CaixaDialeto`: for every arm in
2624 // [`CaixaDialeto::ALL`], the `.try_into()` / `TryFrom::try_from`
2625 // path must resolve to the same variant the sibling
2626 // [`CaixaDialeto::from_wire`] resolver returns on the same
2627 // [`CaixaDialeto::as_str`] wire byte-string input. Pins the
2628 // three-path convergence discipline the [`CaixaDialeto`] closed-
2629 // set typed enum now carries on the `str → Self` reverse-
2630 // projection axis: `<CaixaDialeto as TryFrom<&str>>::try_from(s)`
2631 // (the newly lifted trait-idiomatic reverse projection),
2632 // `CaixaDialeto::from_wire(s)` (the substrate-primitive method-
2633 // named `Option<Self>` accessor the trait impl delegates through),
2634 // and the round-trip identity `variant.as_str() → variant`
2635 // (the four-arm closed accept-set shared between the emitter and
2636 // both reverse-projection consumers) must resolve to the same
2637 // typed [`CaixaDialeto`] discriminator on every arm.
2638 //
2639 // A future silent detour that routes the impl through a
2640 // divergent projection (a per-arm inline
2641 // `match s { "Pacote" => …, … }` re-inlining that opens a
2642 // compile-time link to the un-lifted arm-literal, a swap onto
2643 // the second-axis [`CaixaDialeto::palavra_canonica`] /
2644 // [`CaixaDialeto::consumidor`] / [`CaixaDialeto::descricao`]
2645 // accessors that carry distinct byte-shapes per axis, an accept-
2646 // set widening that silently accepts one axis's byte-shapes as
2647 // parseable on the other axis) trips at caixa-core test time
2648 // under `assert_eq!` rather than at a downstream
2649 // `TryFrom<&str>`-bound consumer's silent split. Peer of the
2650 // sibling
2651 // [`crate::kind::tests::caixa_kind_try_from_str_routes_through_from_wire_accessor`]
2652 // (3c83606) on the top-level [`crate::CaixaKind`] closed-set
2653 // discriminator's reverse-projection axis — extends the trait-
2654 // idiomatic reverse-projection axis onto the seventh closed-set
2655 // fieldless typed enum on the caixa surface (the second one to
2656 // carry the paired `TryFrom<&str>` impl).
2657 for &variant in CaixaDialeto::ALL {
2658 let wire = variant.as_str();
2659 let via_try_from: CaixaDialeto = <CaixaDialeto as TryFrom<&str>>::try_from(wire)
2660 .unwrap_or_else(|()| {
2661 panic!(
2662 "CaixaDialeto::try_from({wire:?}) must accept every \
2663 CaixaDialeto::as_str output — got Err(()) for the \
2664 wire byte-string of {variant:?}"
2665 )
2666 });
2667 let via_from_wire: CaixaDialeto = CaixaDialeto::from_wire(wire).unwrap_or_else(|| {
2668 panic!(
2669 "CaixaDialeto::from_wire({wire:?}) must accept every \
2670 CaixaDialeto::as_str output — got None for the wire \
2671 byte-string of {variant:?}"
2672 )
2673 });
2674 assert_eq!(
2675 via_try_from, variant,
2676 "CaixaDialeto::try_from(CaixaDialeto::{variant:?}.as_str()) \
2677 must return CaixaDialeto::{variant:?} — the trait-idiomatic \
2678 reverse projection must land on the same arm the method-named \
2679 from_wire resolver does",
2680 );
2681 assert_eq!(
2682 via_try_from, via_from_wire,
2683 "CaixaDialeto::try_from({wire:?}) ({via_try_from:?}) must \
2684 byte-equal CaixaDialeto::from_wire({wire:?}) ({via_from_wire:?}) \
2685 on the same input — divergence signals a silent detour off the \
2686 shared substrate-primitive resolver",
2687 );
2688 assert_eq!(
2689 <CaixaDialeto as TryFrom<&str>>::try_from(wire).ok(),
2690 CaixaDialeto::from_wire(wire),
2691 "the Result::ok() projection of TryFrom<&str> must byte-equal \
2692 the sibling from_wire Option<Self> output on {wire:?} — the \
2693 two accessors must share the same accept-set and typed \
2694 outcome per arm",
2695 );
2696 }
2697 }
2698
2699 #[test]
2700 fn caixa_dialeto_try_from_str_rejects_unknown_byte_strings() {
2701 // Rejection witness on the trait-idiomatic reverse-projection
2702 // axis: any string outside the four-arm [`CaixaDialeto::as_str`]
2703 // output set must resolve to `Err(())` through the lifted
2704 // [`impl TryFrom<&str> for CaixaDialeto`]. A future accidental
2705 // widening of the accept-set (a case-insensitive match that
2706 // accepts `"pacote"` on the wire axis, a hand-rolled Levenshtein-
2707 // forgiving arm-lookup that admits `"Pacotee"` typos, a silent
2708 // acceptance of the sibling [`CaixaDialeto::palavra_canonica`]
2709 // `"defcaixa"` / `"defmolde"` byte-shapes on this axis, a swap
2710 // onto the [`CaixaDialeto::consumidor`] `"pleme-doc-gen"` /
2711 // `"caixa-core / feira"` / `"nobody known"` byte-shapes) would
2712 // silently drift the trait-idiomatic parser's accept-set from
2713 // the sibling [`CaixaDialeto::from_wire`] resolver's — a
2714 // downstream `TryFrom<&str>`-bound consumer binding a malformed
2715 // byte-string through this impl would then bind a plausibly-
2716 // wrong typed arm the caller does not route through any fallback,
2717 // silently misclassifying the reloaded row.
2718 //
2719 // Sweeps the same rejection set the sibling
2720 // [`caixa_dialeto_from_wire_rejects_unknown_byte_strings`] pin
2721 // walks (the shared `from_wire` resolver both accessors delegate
2722 // through) so the trait-idiomatic axis and the method-named axis
2723 // stay locked to the same accept-set by construction. Peer of the
2724 // sibling
2725 // [`crate::kind::tests::caixa_kind_try_from_str_rejects_unknown_byte_strings`]
2726 // (3c83606) on the top-level [`crate::CaixaKind`] closed-set
2727 // discriminator's trait-idiomatic reverse-projection axis.
2728 for bad in [
2729 "",
2730 " ",
2731 "pacote",
2732 "PACOTE",
2733 "molde",
2734 "MoldePositional",
2735 "desconhecido",
2736 "Unknown",
2737 "defcaixa",
2738 "defmolde",
2739 "?",
2740 "caixa-core / feira",
2741 "pleme-doc-gen",
2742 "nobody known",
2743 "Pacote ",
2744 " Pacote",
2745 ] {
2746 assert_eq!(
2747 <CaixaDialeto as TryFrom<&str>>::try_from(bad),
2748 Err(()),
2749 "CaixaDialeto::try_from({bad:?}) must return Err(()) — the \
2750 trait-idiomatic parser's accept-set is exactly the four \
2751 CaixaDialeto::as_str outputs; a widening would silently \
2752 split the trait-idiomatic reverse-projection axis from the \
2753 sibling from_wire resolver's arm-set"
2754 );
2755 }
2756 }
2757
2758 #[test]
2759 fn caixa_dialeto_from_into_static_str_routes_through_as_str_accessor() {
2760 // Fail-before-pass-after byte-parity pin on the newly lifted
2761 // `impl From<CaixaDialeto> for &'static str` — asserts the
2762 // standard-library trait impl and the substrate-primitive
2763 // [`CaixaDialeto::as_str`] `pub const fn` accessor resolve to
2764 // the same four-arm emit-set across every arm the exhaustive
2765 // [`CaixaDialeto::ALL`] slice enumerates. Any future silent
2766 // detour that routes the trait impl through a divergent
2767 // projection (a per-arm inline `match dialeto { Pacote =>
2768 // "Pacote", … }` re-inlining that opens a compile-time link to
2769 // the un-lifted arm-literal, an accidental swap onto the second-
2770 // axis [`CaixaDialeto::palavra_canonica`] /
2771 // [`CaixaDialeto::consumidor`] / [`CaixaDialeto::descricao`]
2772 // accessors that carry distinct byte-shapes per axis) trips at
2773 // caixa-core test time under `assert_eq!` rather than at a
2774 // downstream `impl Into<&'static str>`-bound consumer's silent
2775 // split. Sweeps every one of the four arms [`CaixaDialeto::ALL`]
2776 // carries so no arm's projection is covered only by the sibling
2777 // method-named `as_str` / [`std::fmt::Display`] / [`AsRef<str>`]
2778 // paths. Materializes the `<&'static str as
2779 // From<CaixaDialeto>>::from` output in a `const`-shape binding
2780 // to make the `'static` lifetime promise a build-time invariant
2781 // — a future accidental downgrade of any of the four arms'
2782 // returned literals to a non-`&'static str` (a `String::leak()`-
2783 // produced return, a `Box::leak`-cast, an intermediate lifetime-
2784 // erasing helper) trips at caixa-core build time rather than at
2785 // a downstream `'static`-bound consumer. Peer of the sibling
2786 // [`crate::supervisor::tests::restart_strategy_from_into_static_str_routes_through_as_str_accessor`]
2787 // (523157d) /
2788 // [`crate::supervisor::tests::restart_policy_from_into_static_str_routes_through_as_str_accessor`]
2789 // (9fb37d0) /
2790 // [`crate::kind::tests::caixa_kind_from_into_static_str_routes_through_as_str_accessor`]
2791 // (edb827b) pins on the sibling closed-set typed-enum forward-
2792 // projection axes — extends the trait-idiomatic forward-
2793 // projection axis onto the fourth closed-set fieldless typed
2794 // enum on the caixa surface (the dialect-classification axis,
2795 // second-of-two closed-set typed enums in caixa-core outside
2796 // the OTP-shape M2 slot).
2797 const PACOTE: &str = CaixaDialeto::Pacote.as_str();
2798 const MOLDE: &str = CaixaDialeto::Molde.as_str();
2799 const MOLDE_POSICIONAL: &str = CaixaDialeto::MoldePosicional.as_str();
2800 const DESCONHECIDO: &str = CaixaDialeto::Desconhecido.as_str();
2801 for &variant in CaixaDialeto::ALL {
2802 let via_trait: &'static str = <&'static str as From<CaixaDialeto>>::from(variant);
2803 let via_method: &'static str = variant.as_str();
2804 assert_eq!(
2805 via_trait, via_method,
2806 "From<CaixaDialeto> for &'static str impl must round-trip \
2807 CaixaDialeto::{variant:?} to the same `PascalCase` byte-string \
2808 CaixaDialeto::as_str returns — divergence signals a silent \
2809 detour off the substrate-primitive accessor"
2810 );
2811 let via_into: &'static str = variant.into();
2812 assert_eq!(
2813 via_into, via_method,
2814 "Into<&'static str>::into on CaixaDialeto::{variant:?} must \
2815 byte-equal CaixaDialeto::as_str on the same input — the \
2816 blanket-derived Into shape must resolve to the same as_str \
2817 dispatch as the explicit From impl"
2818 );
2819 }
2820 assert_eq!(
2821 [PACOTE, MOLDE, MOLDE_POSICIONAL, DESCONHECIDO],
2822 ["Pacote", "Molde", "MoldePosicional", "Desconhecido"],
2823 "const-context CaixaDialeto::as_str must resolve to the four \
2824 `PascalCase` variant-name byte-strings — a future accidental \
2825 downgrade of any arm to a non-const or non-static byte-string \
2826 breaks the `&'static str`-lifetime promise the paired \
2827 From<CaixaDialeto> for &'static str impl carries by \
2828 construction"
2829 );
2830 }
2831
2832 #[test]
2833 fn caixa_dialeto_from_into_static_str_and_as_str_partition_the_emit_set() {
2834 // Cross-axis partition pin: the paired trait-idiomatic
2835 // `From<CaixaDialeto> for &'static str` forward projection and
2836 // the method-named [`CaixaDialeto::as_str`] forward projection
2837 // must resolve identically on *every* arm, not just the ones
2838 // named in the primary byte-parity pin above. Sweeps every
2839 // [`CaixaDialeto::ALL`] arm and asserts the trait's `From::from`
2840 // output byte-equals the method-named accessor's return-value on
2841 // each, locking the two forward-projection paths together by
2842 // construction so any future detour (a stray `From` special-case
2843 // that lands on a divergent per-arm literal outside the paired
2844 // `as_str` dispatch, a hypothetical rebrand touching one axis
2845 // without the other) trips at caixa-core test time. Peer of the
2846 // sibling forward-projection partition pins
2847 // [`crate::supervisor::tests::restart_strategy_from_into_static_str_and_as_str_partition_the_emit_set`]
2848 // (523157d) /
2849 // [`crate::supervisor::tests::restart_policy_from_into_static_str_and_as_str_partition_the_emit_set`]
2850 // (9fb37d0) /
2851 // [`crate::kind::tests::caixa_kind_from_into_static_str_and_as_str_partition_the_emit_set`]
2852 // (edb827b) — extends the round-trip discipline onto the fourth
2853 // closed-set typed enum on the caixa surface, closing the two-way
2854 // `Self ↔ &'static str` round-trip on the trait-idiomatic pair
2855 // (`From<Self> for &'static str` + `TryFrom<&str> for Self`) as
2856 // well as the pre-existing method-named pair (`as_str` +
2857 // `from_wire`).
2858 for &variant in CaixaDialeto::ALL {
2859 let via_trait: &'static str = <&'static str as From<CaixaDialeto>>::from(variant);
2860 let via_method: &'static str = variant.as_str();
2861 assert_eq!(
2862 via_trait, via_method,
2863 "From<CaixaDialeto> for &'static str and \
2864 CaixaDialeto::as_str must resolve identically on \
2865 CaixaDialeto::{variant:?} — divergence signals the \
2866 two forward-projection paths have drifted onto different \
2867 emit-sets"
2868 );
2869 }
2870 // Round-trip witness: every arm's forward `From` output re-parses
2871 // through the paired trait-idiomatic reverse `TryFrom<&str>` back
2872 // to the original variant. Closes the two-way `CaixaDialeto ↔
2873 // &'static str` round-trip on the trait-idiomatic axis pair
2874 // directly (no wire-vocab intermediate the peer [`CaixaKind`]
2875 // axis pair requires — the emit-side [`CaixaDialeto::as_str`]
2876 // and the parse-side [`CaixaDialeto::from_wire`] share the same
2877 // `PascalCase` byte-string vocabulary by construction), mirroring
2878 // the pre-existing method-named `as_str` + `from_wire` round-trip
2879 // on the substrate-primitive axis pair.
2880 for &variant in CaixaDialeto::ALL {
2881 let emitted: &'static str = variant.into();
2882 let re_parsed: Result<CaixaDialeto, ()> =
2883 <CaixaDialeto as TryFrom<&str>>::try_from(emitted);
2884 assert_eq!(
2885 re_parsed,
2886 Ok(variant),
2887 "trait-idiomatic axis pair must round-trip \
2888 CaixaDialeto::{variant:?} through `.into::<&'static \
2889 str>()` and back through `TryFrom<&str>` — a break signals \
2890 the forward-emit and reverse-parse axes have drifted onto \
2891 different vocabularies"
2892 );
2893 }
2894 }
2895
2896 #[test]
2897 fn caixa_dialeto_is_molde_family_routes_through_is_variant_derived_predicates() {
2898 // Byte-parity pin on the post-lift [`CaixaDialeto::is_molde_family`]
2899 // convergence: for every arm in [`CaixaDialeto::ALL`], the typed
2900 // predicate must byte-equal the direct
2901 // `self.is_molde() || self.is_molde_posicional()` composition of
2902 // the two derived per-arm predicates. Pre-lift the predicate
2903 // hand-rolled `matches!(self, Self::Molde | Self::MoldePosicional)`
2904 // with no compile-time link back to the closed-set typed dispatch;
2905 // post-lift it routes through the derived predicates so a future
2906 // arm rename or `#[is_variant(name = "…")]` override lands at
2907 // exactly one dispatch on the substrate primitive. Pinning the
2908 // byte-equality here refuses a future accidental split between
2909 // the composed predicate and the paired derived predicates
2910 // (a hand-rolled shadow `impl` that overrides one path but not
2911 // the other, an accidental rebrand of `is_molde_family`'s body
2912 // back to the pre-lift `matches!` form) at caixa-core build time.
2913 for &d in CaixaDialeto::ALL {
2914 let via_derived = d.is_molde() || d.is_molde_posicional();
2915 let via_is_molde_family = d.is_molde_family();
2916 assert_eq!(
2917 via_is_molde_family, via_derived,
2918 "CaixaDialeto::{d:?}.is_molde_family() ({via_is_molde_family}) \
2919 must byte-equal the composed derived predicates \
2920 is_molde() || is_molde_posicional() ({via_derived}) — a \
2921 split between the composed predicate and its derived \
2922 building blocks would let a future arm rename land at one \
2923 path and drift at the other, which is exactly the drift \
2924 the IsVariant lift refuses"
2925 );
2926 }
2927 }
2928
2929 #[test]
2930 fn caixa_dialeto_from_borrowed_into_static_str_routes_through_as_str_accessor() {
2931 // Fail-before-pass-after byte-parity pin on the newly lifted
2932 // `impl From<&CaixaDialeto> for &'static str` — asserts the
2933 // borrowed-input standard-library trait impl and the substrate-
2934 // primitive [`CaixaDialeto::as_str`] `pub const fn` accessor
2935 // resolve to the same four-arm emit-set across every arm the
2936 // exhaustive [`CaixaDialeto::ALL`] slice enumerates. Rust's
2937 // `From` trait does not auto-derive the borrowed-input sibling
2938 // from a paired owned-input impl (no `impl<T, U> From<&T> for U
2939 // where T: Copy, U: From<T>` blanket in `core`), so the
2940 // borrowed-input axis is a distinct trait-idiomatic surface that
2941 // a `.iter().map(Into::into)` shape over [`CaixaDialeto::ALL`]
2942 // (whose iterator yields `&CaixaDialeto`, not `CaixaDialeto`)
2943 // reaches through this impl and no other — the paired owned-
2944 // input [`From<CaixaDialeto>`] impl requires an explicit
2945 // `.copied()` / dereference before the trait fires.
2946 // Materializes the `<&'static str as From<&CaixaDialeto>>::from`
2947 // output in a `const`-shape binding to make the `'static`
2948 // lifetime promise a build-time invariant — a future accidental
2949 // downgrade of any of the four arms' returned literals to a
2950 // non-`&'static str` trips at caixa-core build time rather than
2951 // at a downstream `'static`-bound consumer. Peer of the sibling
2952 // [`crate::dep::tests::dep_list_from_borrowed_into_static_str_routes_through_as_str_accessor`]
2953 // (64aa742) /
2954 // [`crate::kind::tests::caixa_kind_from_borrowed_into_static_str_routes_through_as_str_accessor`]
2955 // (5ab993a) pins on the sibling closed-set typed-enum borrowed-
2956 // input forward-projection axes — extends the borrowed-input
2957 // axis discipline onto the third peer on the substrate-wide
2958 // campaign, the dialect-classification axis.
2959 const PACOTE: &str = CaixaDialeto::Pacote.as_str();
2960 const MOLDE: &str = CaixaDialeto::Molde.as_str();
2961 const MOLDE_POSICIONAL: &str = CaixaDialeto::MoldePosicional.as_str();
2962 const DESCONHECIDO: &str = CaixaDialeto::Desconhecido.as_str();
2963 for variant in CaixaDialeto::ALL {
2964 let via_trait: &'static str = <&'static str as From<&CaixaDialeto>>::from(variant);
2965 let via_method: &'static str = variant.as_str();
2966 assert_eq!(
2967 via_trait, via_method,
2968 "From<&CaixaDialeto> for &'static str impl must round-trip \
2969 &CaixaDialeto::{variant:?} to the same `PascalCase` byte-\
2970 string CaixaDialeto::as_str returns — divergence signals a \
2971 silent detour off the substrate-primitive accessor"
2972 );
2973 let via_into: &'static str = variant.into();
2974 assert_eq!(
2975 via_into, via_method,
2976 "Into<&'static str>::into on &CaixaDialeto::{variant:?} must \
2977 byte-equal CaixaDialeto::as_str on the same input — the \
2978 blanket-derived Into shape must resolve to the same as_str \
2979 dispatch as the explicit From impl"
2980 );
2981 }
2982 assert_eq!(
2983 [PACOTE, MOLDE, MOLDE_POSICIONAL, DESCONHECIDO],
2984 ["Pacote", "Molde", "MoldePosicional", "Desconhecido"],
2985 "const-context CaixaDialeto::as_str must resolve to the four \
2986 `PascalCase` variant-name byte-strings — the borrowed-input \
2987 From<&CaixaDialeto> for &'static str impl inherits its \
2988 `'static` lifetime promise from the same accessor the owned-\
2989 input sibling routes through"
2990 );
2991 }
2992
2993 #[test]
2994 fn caixa_dialeto_from_owned_and_borrowed_into_static_str_agree_on_every_arm() {
2995 // Cross-axis partition pin: the paired trait-idiomatic
2996 // owned-input `From<CaixaDialeto> for &'static str` and
2997 // borrowed-input `From<&CaixaDialeto> for &'static str` (this
2998 // lift) forward projections must resolve identically on every
2999 // arm, locking the two input-shape paths together so any future
3000 // detour trips at caixa-core test time. Then a witness that a
3001 // `.iter().map(Into::into)` pipe over [`CaixaDialeto::ALL`]
3002 // (whose iterator yields `&CaixaDialeto`) materializes the four-
3003 // arm accept-set through the borrowed-input axis alone — the
3004 // exact shape a future M4 admission-webhook rejection body
3005 // composer, a future substrate-wide per-arm diagnostic column,
3006 // or a `HashMap::<&'static str, CaixaDialeto>::from_iter(
3007 // CaixaDialeto::ALL.iter().map(|d| (d.into(), *d)))`-style
3008 // per-dialect lookup reaches through — closing the two-way
3009 // owned/borrowed input-shape symmetry on the forward-projection
3010 // trait-idiomatic axis. Peer of the sibling
3011 // [`crate::dep::tests::dep_list_from_owned_and_borrowed_into_static_str_agree_on_every_arm`]
3012 // (64aa742) /
3013 // [`crate::kind::tests::caixa_kind_from_owned_and_borrowed_into_static_str_agree_on_every_arm`]
3014 // (5ab993a) partition pins — extends the borrowed-input axis
3015 // discipline onto the third peer on the substrate-wide campaign.
3016 for &variant in CaixaDialeto::ALL {
3017 let owned: &'static str = <&'static str as From<CaixaDialeto>>::from(variant);
3018 let borrowed: &'static str = <&'static str as From<&CaixaDialeto>>::from(&variant);
3019 assert_eq!(
3020 owned, borrowed,
3021 "From<CaixaDialeto> and From<&CaixaDialeto> for &'static str \
3022 must resolve identically on CaixaDialeto::{variant:?} — \
3023 divergence signals the owned-input and borrowed-input \
3024 forward-projection paths have drifted onto different \
3025 emit-sets"
3026 );
3027 }
3028 let via_iter: Vec<&'static str> = CaixaDialeto::ALL.iter().map(Into::into).collect();
3029 let via_method: Vec<&'static str> = CaixaDialeto::ALL.iter().map(|d| d.as_str()).collect();
3030 assert_eq!(
3031 via_iter, via_method,
3032 "`.iter().map(Into::into)` over CaixaDialeto::ALL must byte-\
3033 equal `.iter().map(|d| d.as_str())` on every arm — the \
3034 borrowed-input `From<&CaixaDialeto> for &'static str` axis \
3035 is what makes the `.iter().map(Into::into)` shape route \
3036 through the substrate-primitive `CaixaDialeto::as_str` \
3037 accessor rather than through a per-call-site `.copied()` / \
3038 dereference detour"
3039 );
3040 // Direct round-trip witness on the borrowed-input axis: every
3041 // arm's borrowed `From` output re-parses through the paired
3042 // trait-idiomatic reverse `TryFrom<&str>` back to the original
3043 // variant. Unlike the peer [`crate::CaixaKind`] axis pair
3044 // (whose forward `From<Self> for &'static str` emits the
3045 // lowercase Portuguese `as_str` diagnostic vocabulary while
3046 // the reverse `TryFrom<&str>` parses the `PascalCase`
3047 // `wire_name` author-surface vocabulary, forcing the round-trip
3048 // through an intermediate wire-vocab hop), [`CaixaDialeto`]'s
3049 // [`CaixaDialeto::as_str`] emit and [`CaixaDialeto::from_wire`]
3050 // parse share the same `PascalCase` vocabulary by construction,
3051 // so the borrowed-input forward axis and the reverse axis
3052 // compose directly.
3053 for &variant in CaixaDialeto::ALL {
3054 let borrowed: &'static str = <&'static str as From<&CaixaDialeto>>::from(&variant);
3055 let re_parsed: Result<CaixaDialeto, ()> =
3056 <CaixaDialeto as TryFrom<&str>>::try_from(borrowed);
3057 assert_eq!(
3058 re_parsed,
3059 Ok(variant),
3060 "trait-idiomatic borrowed-input round-trip must project \
3061 &CaixaDialeto::{variant:?} through \
3062 `<&'static str>::from(&variant)` and back through \
3063 `TryFrom<&str>` — a break signals the borrowed-input \
3064 forward-emit axis and the reverse-parse axis have \
3065 drifted onto different vocabularies"
3066 );
3067 }
3068 }
3069
3070 #[test]
3071 fn caixa_dialeto_from_into_owned_string_routes_through_as_str_accessor() {
3072 // Fail-before-pass-after byte-parity pin on the newly lifted
3073 // `impl From<CaixaDialeto> for String` — asserts the owned-`String`
3074 // -returning standard-library trait impl and the substrate-
3075 // primitive [`CaixaDialeto::as_str`] `pub const fn` accessor
3076 // resolve to the same four-arm emit-set across every arm the
3077 // exhaustive [`CaixaDialeto::ALL`] slice enumerates. Rust's
3078 // standard library does not carry a blanket
3079 // `impl<T: AsRef<str>> From<T> for String` (nor an
3080 // `impl<T: fmt::Display> From<T> for String`), so the
3081 // owned-`String` forward-projection axis is a distinct trait-
3082 // idiomatic surface that a `let key: String = dialeto.into();`-
3083 // shaped call site reaches through this impl and no other — the
3084 // paired sibling `From<CaixaDialeto> for &'static str` impl
3085 // forces every owned-`String` call site through an explicit
3086 // `.to_owned()` / `String::from` restatement. Peer of the
3087 // first-mover
3088 // [`crate::supervisor::tests::restart_strategy_from_into_owned_string_routes_through_as_str_accessor`]
3089 // (7baa18a), the second-peer
3090 // [`crate::supervisor::tests::restart_policy_from_into_owned_string_routes_through_as_str_accessor`]
3091 // (7851725), and the third-peer
3092 // [`crate::kind::tests::caixa_kind_from_into_owned_string_routes_through_as_str_accessor`]
3093 // (231a18c) — extends the trait-idiomatic owned-`String`
3094 // forward-projection axis onto the fourth closed-set fieldless
3095 // typed enum on the caixa surface (the dialect-classification
3096 // axis, second peer outside the M2 OTP-shape sibling axis).
3097 for &variant in CaixaDialeto::ALL {
3098 let via_trait: String = <String as From<CaixaDialeto>>::from(variant);
3099 let via_method: &'static str = variant.as_str();
3100 assert_eq!(
3101 via_trait.as_str(),
3102 via_method,
3103 "From<CaixaDialeto> for String impl must round-trip \
3104 CaixaDialeto::{variant:?} to the same `PascalCase` \
3105 arm-string CaixaDialeto::as_str returns — divergence \
3106 signals a silent detour off the substrate-primitive \
3107 accessor"
3108 );
3109 let via_into: String = variant.into();
3110 assert_eq!(
3111 via_into.as_str(),
3112 via_method,
3113 "Into<String>::into on CaixaDialeto::{variant:?} must \
3114 byte-equal CaixaDialeto::as_str on the same input — the \
3115 blanket-derived Into shape must resolve to the same \
3116 as_str dispatch as the explicit From impl"
3117 );
3118 }
3119 }
3120
3121 #[test]
3122 fn caixa_dialeto_from_into_owned_string_and_static_str_agree_on_every_arm() {
3123 // Cross-axis partition pin: the paired trait-idiomatic
3124 // owned-`String` `From<CaixaDialeto> for String` (this lift) and
3125 // owned-`&'static str` `From<CaixaDialeto> for &'static str`
3126 // (c189a6f) forward projections must resolve identically on
3127 // every arm, locking the two return-type-shape paths together
3128 // so any future detour trips at caixa-core test time. Also
3129 // byte-parity witness against the sibling
3130 // [`ToString::to_string`] surface routed through
3131 // [`std::fmt::Display`] — the three owned-heap-string paths
3132 // (`.into::<String>()`, `String::from`, `.to_string()`) must
3133 // resolve identically on every arm so a future consumer that
3134 // picks any of the three lands on the same four-arm
3135 // `PascalCase` accept-set. Then a `.iter().copied()
3136 // .map(String::from)` pipe witness over [`CaixaDialeto::ALL`]
3137 // that materializes the four-arm accept-set through the
3138 // owned-`String` axis alone — the exact shape a future M4
3139 // admission-webhook rejection body composer or a
3140 // `HashMap::<String, CaixaDialeto>::from_iter(
3141 // CaixaDialeto::ALL.iter().copied().map(|d| (d.into(), d)))`-
3142 // style owned-key per-dialect lookup reaches through — closing
3143 // the owned-`String` forward-projection axis's iterator-pipe
3144 // shape. Then a direct round-trip witness through the paired
3145 // trait-idiomatic reverse [`TryFrom<&str>`] axis on the
3146 // owned-`String`'s [`String::as_str`] borrow that closes the
3147 // two-way `Self → String → Self` round-trip on the trait-
3148 // idiomatic owned-`String` forward + reverse axis pair.
3149 //
3150 // Unlike the peer [`crate::CaixaKind`] axis pair (whose forward
3151 // `From` emit lands on the lowercase Portuguese `as_str`
3152 // diagnostic vocabulary while the reverse `TryFrom<&str>` parses
3153 // the `PascalCase` `wire_name` author-surface vocabulary,
3154 // forcing the round-trip through an intermediate
3155 // [`crate::CaixaKind::wire_name`] hop), [`CaixaDialeto`]'s
3156 // [`CaixaDialeto::as_str`] emit and [`CaixaDialeto::from_wire`]
3157 // parse share the same `PascalCase` vocabulary by construction
3158 // (there is no wire/diagnostic axis split on this enum), so
3159 // the owned-`String` forward axis and the reverse axis compose
3160 // directly — matching the peer
3161 // [`crate::supervisor::RestartStrategy`] /
3162 // [`crate::supervisor::RestartPolicy`] owned-`String` axis
3163 // pairs (whose forward emit and reverse parse also share one
3164 // `PascalCase` vocabulary by construction).
3165 for &variant in CaixaDialeto::ALL {
3166 let owned_string: String = <String as From<CaixaDialeto>>::from(variant);
3167 let owned_static: &'static str = <&'static str as From<CaixaDialeto>>::from(variant);
3168 assert_eq!(
3169 owned_string.as_str(),
3170 owned_static,
3171 "From<CaixaDialeto> for String and From<CaixaDialeto> for \
3172 &'static str must resolve identically on \
3173 CaixaDialeto::{variant:?} — divergence signals the \
3174 owned-`String` and owned-`&'static str` forward-\
3175 projection return-type-shape paths have drifted onto \
3176 different emit-sets"
3177 );
3178 let via_to_string: String = variant.to_string();
3179 assert_eq!(
3180 owned_string, via_to_string,
3181 "From<CaixaDialeto> for String must byte-equal \
3182 CaixaDialeto::to_string on CaixaDialeto::{variant:?} — \
3183 divergence signals the trait-idiomatic owned-`String` \
3184 forward-projection axis and the ToString-through-\
3185 Display axis have drifted onto different emit-sets"
3186 );
3187 }
3188 let via_iter: Vec<String> = CaixaDialeto::ALL
3189 .iter()
3190 .copied()
3191 .map(String::from)
3192 .collect();
3193 let via_method: Vec<String> = CaixaDialeto::ALL
3194 .iter()
3195 .map(|d| d.as_str().to_owned())
3196 .collect();
3197 assert_eq!(
3198 via_iter, via_method,
3199 "`.iter().copied().map(String::from)` over CaixaDialeto::ALL \
3200 must byte-equal `.iter().map(|d| d.as_str().to_owned())` on \
3201 every arm — the owned-`String` `From<CaixaDialeto> for \
3202 String` axis is what makes the `String::from` composition \
3203 route through the substrate-primitive `CaixaDialeto::as_str` \
3204 accessor rather than through a per-call-site `.to_owned()` / \
3205 `String::from(dialeto.as_str())` detour"
3206 );
3207 for &variant in CaixaDialeto::ALL {
3208 let emitted: String = variant.into();
3209 let re_parsed: Result<CaixaDialeto, ()> =
3210 <CaixaDialeto as TryFrom<&str>>::try_from(emitted.as_str());
3211 assert_eq!(
3212 re_parsed,
3213 Ok(variant),
3214 "trait-idiomatic owned-`String` forward-projection + \
3215 reverse-projection axis pair must round-trip \
3216 CaixaDialeto::{variant:?} through `.into::<String>()` \
3217 and back through `TryFrom<&str>` on the owned-`String`'s \
3218 String::as_str borrow — a break signals the owned-\
3219 `String` forward-emit and reverse-parse axes have \
3220 drifted onto different vocabularies (unlike the peer \
3221 CaixaKind axis pair, CaixaDialeto's forward emit and \
3222 reverse parse share one PascalCase vocabulary by \
3223 construction, so the round-trip composes directly)"
3224 );
3225 }
3226 }
3227
3228 #[test]
3229 fn caixa_dialeto_from_into_borrowed_owned_string_routes_through_as_str_accessor() {
3230 // Fail-before-pass-after byte-parity pin on the newly lifted
3231 // `impl From<&CaixaDialeto> for String` — asserts the borrowed-
3232 // input owned-`String`-returning standard-library trait impl and
3233 // the substrate-primitive [`super::CaixaDialeto::as_str`]
3234 // `pub const fn` accessor resolve to the same four-arm emit-set
3235 // across every arm the exhaustive [`super::CaixaDialeto::ALL`]
3236 // slice enumerates. Rust's standard library does not carry a
3237 // blanket `impl<T: AsRef<str>> From<&T> for String` (nor an
3238 // `impl<T: fmt::Display> From<&T> for String`), so the
3239 // borrowed-input owned-`String` forward-projection axis is a
3240 // distinct trait-idiomatic surface that a
3241 // `let key: String = (&dialeto).into();`-shaped call site
3242 // reaches through this impl and no other — the paired sibling
3243 // `From<CaixaDialeto> for String` impl forces every borrowed-
3244 // input call site through an explicit `Copy` deref
3245 // (`String::from(*dialeto)`) or an `.as_str().to_owned()` /
3246 // `.to_string()` detour. Peer of the first-mover
3247 // [`crate::supervisor::tests::restart_strategy_from_into_borrowed_owned_string_routes_through_as_str_accessor`]
3248 // (579385f), the second-peer
3249 // [`crate::supervisor::tests::restart_policy_from_into_borrowed_owned_string_routes_through_as_str_accessor`]
3250 // (8465740), the third-peer
3251 // [`crate::dep::tests::dep_list_from_into_borrowed_owned_string_routes_through_as_str_accessor`]
3252 // (e0cb617), and the fourth-peer
3253 // [`crate::kind::tests::caixa_kind_from_into_borrowed_owned_string_routes_through_as_str_accessor`]
3254 // (e76436d) — extends the trait-idiomatic borrowed-input owned-
3255 // `String` forward-projection axis onto the fourth closed-set
3256 // fieldless typed enum on the caixa surface (the dialect-
3257 // classification axis, second peer outside the M2 OTP-shape
3258 // sibling axis to reach the 2×2-completion corner).
3259 for &variant in CaixaDialeto::ALL {
3260 let via_trait: String = <String as From<&CaixaDialeto>>::from(&variant);
3261 let via_method: &'static str = variant.as_str();
3262 assert_eq!(
3263 via_trait.as_str(),
3264 via_method,
3265 "From<&CaixaDialeto> for String impl must round-trip \
3266 &CaixaDialeto::{variant:?} to the same `PascalCase` \
3267 arm-string CaixaDialeto::as_str returns — divergence \
3268 signals a silent detour off the substrate-primitive \
3269 accessor"
3270 );
3271 let via_into: String = (&variant).into();
3272 assert_eq!(
3273 via_into.as_str(),
3274 via_method,
3275 "Into<String>::into on &CaixaDialeto::{variant:?} must \
3276 byte-equal CaixaDialeto::as_str on the same input — \
3277 the blanket-derived Into shape must resolve to the \
3278 same as_str dispatch as the explicit From impl"
3279 );
3280 }
3281 }
3282
3283 #[test]
3284 fn caixa_dialeto_from_into_borrowed_owned_string_agrees_with_paired_axes_on_every_arm() {
3285 // Cross-axis partition pin: the newly lifted trait-idiomatic
3286 // borrowed-input owned-`String` `From<&CaixaDialeto> for String`
3287 // (this lift), the paired owned-input owned-`String`
3288 // `From<CaixaDialeto> for String` (88942cd), the paired
3289 // borrowed-input owned-`&'static str`
3290 // `From<&CaixaDialeto> for &'static str` (807b0b5), and the
3291 // paired owned-input owned-`&'static str`
3292 // `From<CaixaDialeto> for &'static str` (c189a6f) — every corner
3293 // of the `{Self, &Self} × {&'static str, String}` 2×2 trait-
3294 // idiomatic projection family — must resolve identically on
3295 // every arm, locking the four return-shape × input-shape paths
3296 // together so any future detour trips at caixa-core test time.
3297 // Also byte-parity witness against the sibling
3298 // [`ToString::to_string`] surface routed through
3299 // [`std::fmt::Display`] and a direct round-trip witness through
3300 // the paired trait-idiomatic reverse [`TryFrom<&str>`] axis on
3301 // the owned-`String`'s [`String::as_str`] borrow that closes
3302 // the two-way `&Self → String → Self` round-trip on the trait-
3303 // idiomatic borrowed-input owned-`String` forward + reverse
3304 // axis pair. Peer of the first-mover
3305 // [`crate::supervisor::tests::restart_strategy_from_into_borrowed_owned_string_agrees_with_paired_axes_on_every_arm`]
3306 // (579385f), the second-peer
3307 // [`crate::supervisor::tests::restart_policy_from_into_borrowed_owned_string_agrees_with_paired_axes_on_every_arm`]
3308 // (8465740), the third-peer
3309 // [`crate::dep::tests::dep_list_from_into_borrowed_owned_string_agrees_with_paired_axes_on_every_arm`]
3310 // (e0cb617), and the fourth-peer
3311 // [`crate::kind::tests::caixa_kind_from_into_borrowed_owned_string_agrees_with_paired_axes_on_every_arm`]
3312 // (e76436d) — closes the whole `{Self, &Self} × {&'static str,
3313 // String}` 2×2 projection corner on the fifth substrate-wide
3314 // closed-set fieldless typed enum peer (the dialect-
3315 // classification axis, second peer outside the M2 OTP-shape
3316 // sibling pair).
3317 //
3318 // Unlike the peer [`crate::CaixaKind`] axis pair (whose forward
3319 // `From` emit lands on the lowercase Portuguese `as_str`
3320 // diagnostic vocabulary while the reverse `TryFrom<&str>`
3321 // parses the `PascalCase` `wire_name` author-surface vocabulary,
3322 // forcing the round-trip through an intermediate
3323 // [`crate::CaixaKind::wire_name`] hop), [`super::CaixaDialeto`]'s
3324 // [`super::CaixaDialeto::as_str`] emit and
3325 // [`super::CaixaDialeto::from_wire`] parse share the same
3326 // `PascalCase` vocabulary by construction (there is no
3327 // wire/diagnostic axis split on this enum), so the borrowed-
3328 // input owned-`String` forward axis and the reverse axis compose
3329 // directly — matching the peer
3330 // [`crate::supervisor::RestartStrategy`] /
3331 // [`crate::supervisor::RestartPolicy`] / [`crate::dep::DepList`]
3332 // borrowed-input owned-`String` axis pairs.
3333 for &dialeto in CaixaDialeto::ALL {
3334 let borrowed_string: String = <String as From<&CaixaDialeto>>::from(&dialeto);
3335 let owned_string: String = <String as From<CaixaDialeto>>::from(dialeto);
3336 let borrowed_static: &'static str =
3337 <&'static str as From<&CaixaDialeto>>::from(&dialeto);
3338 let owned_static: &'static str = <&'static str as From<CaixaDialeto>>::from(dialeto);
3339 assert_eq!(
3340 borrowed_string, owned_string,
3341 "From<&CaixaDialeto> for String and From<CaixaDialeto> \
3342 for String must resolve identically on \
3343 CaixaDialeto::{dialeto:?} — divergence signals the \
3344 borrowed-input and owned-input owned-`String` forward-\
3345 projection input-shape paths have drifted onto \
3346 different emit-sets"
3347 );
3348 assert_eq!(
3349 borrowed_string.as_str(),
3350 borrowed_static,
3351 "From<&CaixaDialeto> for String and From<&CaixaDialeto> \
3352 for &'static str must resolve identically on \
3353 CaixaDialeto::{dialeto:?} — divergence signals the \
3354 borrowed-input `&'static str` and owned-`String` \
3355 return-shape paths have drifted onto different \
3356 emit-sets"
3357 );
3358 assert_eq!(
3359 borrowed_string.as_str(),
3360 owned_static,
3361 "From<&CaixaDialeto> for String and From<CaixaDialeto> \
3362 for &'static str must resolve identically on \
3363 CaixaDialeto::{dialeto:?} — divergence signals a break \
3364 in the diagonal corner of the {{Self, &Self}} × \
3365 {{&'static str, String}} 2×2 trait-idiomatic \
3366 projection family"
3367 );
3368 let via_to_string: String = dialeto.to_string();
3369 assert_eq!(
3370 borrowed_string, via_to_string,
3371 "From<&CaixaDialeto> for String must byte-equal \
3372 CaixaDialeto::to_string on CaixaDialeto::{dialeto:?} — \
3373 divergence signals the trait-idiomatic borrowed-input \
3374 owned-`String` forward-projection axis and the \
3375 ToString-through-Display axis have drifted onto \
3376 different emit-sets"
3377 );
3378 }
3379 let via_iter: Vec<String> = CaixaDialeto::ALL.iter().map(String::from).collect();
3380 let via_method: Vec<String> = CaixaDialeto::ALL
3381 .iter()
3382 .map(|d| d.as_str().to_owned())
3383 .collect();
3384 assert_eq!(
3385 via_iter, via_method,
3386 "`.iter().map(String::from)` over CaixaDialeto::ALL — a \
3387 call site whose iteration axis holds `&CaixaDialeto` by \
3388 construction — must byte-equal `.iter().map(|d| \
3389 d.as_str().to_owned())` on every arm — the borrowed-input \
3390 owned-`String` `From<&CaixaDialeto> for String` axis is \
3391 what makes the `String::from` composition route through \
3392 the substrate-primitive `CaixaDialeto::as_str` accessor \
3393 without a spurious `Copy` deref (which would only be \
3394 reachable through the owned-input `From<CaixaDialeto> for \
3395 String` axis by first calling `.copied()` on the iterator)"
3396 );
3397 for &variant in CaixaDialeto::ALL {
3398 let emitted: String = (&variant).into();
3399 let re_parsed: Result<CaixaDialeto, ()> =
3400 <CaixaDialeto as TryFrom<&str>>::try_from(emitted.as_str());
3401 assert_eq!(
3402 re_parsed,
3403 Ok(variant),
3404 "trait-idiomatic borrowed-input owned-`String` \
3405 forward-projection + reverse-projection axis pair \
3406 must round-trip &CaixaDialeto::{variant:?} through \
3407 `.into::<String>()` on the borrowed-input surface and \
3408 back through `TryFrom<&str>` on the owned-`String`'s \
3409 String::as_str borrow — a break signals the \
3410 borrowed-input owned-`String` forward-emit and \
3411 reverse-parse axes have drifted onto different \
3412 vocabularies (unlike the peer CaixaKind axis pair, \
3413 CaixaDialeto's forward emit and reverse parse share \
3414 one PascalCase vocabulary by construction, so the \
3415 round-trip composes directly)"
3416 );
3417 }
3418 }
3419
3420 #[test]
3421 fn caixa_dialeto_from_into_static_cow_str_routes_through_as_str_accessor() {
3422 // Fail-before-pass-after byte-parity pin on the newly lifted
3423 // `impl From<CaixaDialeto> for std::borrow::Cow<'static, str>`
3424 // — asserts the standard-library trait impl and the
3425 // substrate-primitive [`super::CaixaDialeto::as_str`]
3426 // `pub const fn` accessor resolve to the same four-arm
3427 // emit-set across every arm the exhaustive
3428 // [`super::CaixaDialeto::ALL`] slice enumerates. Rust's
3429 // standard library does not carry a blanket
3430 // `impl<T: AsRef<str>> From<T> for std::borrow::Cow<'static,
3431 // str>` (nor an `impl<T: fmt::Display> From<T> for
3432 // std::borrow::Cow<'static, str>`), so the
3433 // [`std::borrow::Cow<'static, str>`] forward-projection axis
3434 // is a distinct trait-idiomatic surface that a
3435 // `let key: std::borrow::Cow<'static, str> = dialeto.into();`-
3436 // shaped call site reaches through this impl and no other —
3437 // the paired sibling `From<CaixaDialeto> for &'static str`
3438 // and `From<CaixaDialeto> for String` impls force every
3439 // [`std::borrow::Cow<'static, str>`]-parameterized call site
3440 // through a `std::borrow::Cow::Borrowed(dialeto.as_str())` /
3441 // `std::borrow::Cow::Owned(dialeto.to_string())` /
3442 // `String::from(dialeto).into()` composition whose type
3443 // bounds have no compile-time link back to the substrate
3444 // primitive.
3445 //
3446 // Also asserts the projection lands on the zero-alloc
3447 // [`std::borrow::Cow::Borrowed`] arm (not the
3448 // [`std::borrow::Cow::Owned`] arm) — the substrate-primitive
3449 // [`super::CaixaDialeto::as_str`] accessor's `&'static str`
3450 // return lifetime by construction makes the borrowed arm the
3451 // type-correct projection with no runtime allocation. Any
3452 // future silent detour that routes the impl through the
3453 // owned arm (an accidental
3454 // `std::borrow::Cow::Owned(dialeto.to_string())` rewrite that
3455 // would allocate on every call site where the `&'static str`
3456 // return of [`super::CaixaDialeto::as_str`] makes the
3457 // zero-alloc borrowed projection type-correct) trips at
3458 // caixa-core test time under the
3459 // [`std::borrow::Cow::Borrowed`] discriminator witness rather
3460 // than at a downstream
3461 // [`std::borrow::Cow<'static, str>`]-bound consumer's silent
3462 // allocation.
3463 //
3464 // Second peer on the outside-M3 caixa-core tier of the
3465 // substrate-wide trait-idiomatic
3466 // [`std::borrow::Cow<'static, str>`] forward-projection
3467 // family — extends the axis off the two-list dep-graph
3468 // [`crate::dep::DepList`] pair (6858bac / 702cdf4) that
3469 // opened + closed the tier onto the dialect-classification
3470 // [`super::CaixaDialeto`] enum (the sole remaining
3471 // internal-classification peer on the caixa-core surface).
3472 // Every future closed-set fieldless typed enum peer on the
3473 // substrate is a future target of the campaign.
3474 for &variant in CaixaDialeto::ALL {
3475 let via_trait: std::borrow::Cow<'static, str> =
3476 <std::borrow::Cow<'static, str> as From<CaixaDialeto>>::from(variant);
3477 let via_method: &'static str = variant.as_str();
3478 assert_eq!(
3479 via_trait.as_ref(),
3480 via_method,
3481 "From<CaixaDialeto> for Cow<'static, str> impl must \
3482 round-trip CaixaDialeto::{variant:?} to the same \
3483 PascalCase byte-string CaixaDialeto::as_str returns \
3484 — divergence signals a silent detour off the \
3485 substrate-primitive accessor"
3486 );
3487 assert!(
3488 matches!(via_trait, std::borrow::Cow::Borrowed(_)),
3489 "From<CaixaDialeto> for Cow<'static, str> impl must \
3490 land on the zero-alloc Cow::Borrowed arm on \
3491 CaixaDialeto::{variant:?} — a Cow::Owned outcome \
3492 signals the projection has silently allocated where \
3493 the substrate-primitive CaixaDialeto::as_str \
3494 `&'static str` return makes the borrowed arm the \
3495 type-correct projection"
3496 );
3497 let via_into: std::borrow::Cow<'static, str> = variant.into();
3498 assert_eq!(
3499 via_into.as_ref(),
3500 via_method,
3501 "Into<Cow<'static, str>>::into on \
3502 CaixaDialeto::{variant:?} must byte-equal \
3503 CaixaDialeto::as_str on the same input — the \
3504 blanket-derived Into shape must resolve to the same \
3505 as_str dispatch as the explicit From impl"
3506 );
3507 assert!(
3508 matches!(via_into, std::borrow::Cow::Borrowed(_)),
3509 "Into<Cow<'static, str>>::into on \
3510 CaixaDialeto::{variant:?} must land on the zero-alloc \
3511 Cow::Borrowed arm — the blanket-derived Into shape \
3512 must resolve to the same Cow::Borrowed dispatch as \
3513 the explicit From impl"
3514 );
3515 }
3516 }
3517
3518 #[test]
3519 fn caixa_dialeto_from_into_static_cow_str_agrees_with_paired_axes_on_every_arm() {
3520 // Cross-axis partition pin: the newly lifted trait-idiomatic
3521 // `From<CaixaDialeto> for std::borrow::Cow<'static, str>`
3522 // (this lift), the paired owned-input
3523 // `From<CaixaDialeto> for &'static str`, and the paired
3524 // owned-input `From<CaixaDialeto> for String` forward
3525 // projections must resolve identically on every arm, locking
3526 // the three return-shape paths together by construction so
3527 // any future detour trips at caixa-core test time. Also
3528 // byte-parity witness against the sibling
3529 // [`ToString::to_string`] surface routed through
3530 // [`std::fmt::Display`] — every owned-heap-string path (the
3531 // [`std::borrow::Cow::Owned`] promotion of this axis's
3532 // `.into_owned()`, `From<CaixaDialeto> for String`, and
3533 // `.to_string()`) resolves to the same PascalCase byte-string
3534 // per arm.
3535 //
3536 // Then a `.iter().copied().map(std::borrow::Cow::from)` pipe
3537 // witness over [`super::CaixaDialeto::ALL`] that materializes
3538 // the four-arm accept-set through the
3539 // [`std::borrow::Cow<'static, str>`] axis alone — the exact
3540 // shape a future `axum::response::IntoResponse` per-arm
3541 // rejection-body composer, a future M4
3542 // `mesh.pleme.io/v1alpha1/Manifesto` CR materializer's
3543 // admission-webhook per-arm rejection-reason emitter whose
3544 // typing rules out the sibling [`AsRef<str>`] borrowed
3545 // return, or a future substrate-wide per-arm diagnostic
3546 // surface that binds through a
3547 // [`std::borrow::Cow<'static, str>`] boundary reaches through
3548 // — closing the composable-projection axis on the dialect-
3549 // classification closed-set fieldless typed enum peer. The
3550 // pipe witness also pins the zero-alloc discipline: every
3551 // element in the collected vector satisfies the
3552 // [`std::borrow::Cow::Borrowed`] arm predicate, so a future
3553 // accidental silent-allocation regression on the pipe's
3554 // iteration axis is a caixa-core-test-time failure.
3555 //
3556 // Then a direct round-trip witness through
3557 // [`TryFrom<&str>`] on the projection's
3558 // [`std::borrow::Cow::as_ref`] borrow — unlike the peer
3559 // [`crate::CaixaKind`] axis pair (whose forward emit lands
3560 // on the lowercase Portuguese diagnostic vocabulary while
3561 // the reverse parse lands on the `PascalCase` wire
3562 // vocabulary, forcing the round-trip through an intermediate
3563 // [`crate::CaixaKind::wire_name`] hop),
3564 // [`super::CaixaDialeto`]'s forward emit and reverse parse
3565 // share one `PascalCase` vocabulary by construction, so the
3566 // [`std::borrow::Cow<'static, str>`] projection composes
3567 // directly with the trait-idiomatic reverse [`TryFrom<&str>`]
3568 // axis without the wire-vocab intermediate hop.
3569 for &variant in CaixaDialeto::ALL {
3570 let via_cow: std::borrow::Cow<'static, str> =
3571 <std::borrow::Cow<'static, str> as From<CaixaDialeto>>::from(variant);
3572 let via_static: &'static str = <&'static str as From<CaixaDialeto>>::from(variant);
3573 let via_string: String = <String as From<CaixaDialeto>>::from(variant);
3574 assert_eq!(
3575 via_cow.as_ref(),
3576 via_static,
3577 "From<CaixaDialeto> for Cow<'static, str> and \
3578 From<CaixaDialeto> for &'static str must resolve \
3579 identically on CaixaDialeto::{variant:?} — \
3580 divergence signals the Cow<'static, str> and \
3581 &'static str return-shape paths have drifted onto \
3582 different emit-sets"
3583 );
3584 assert_eq!(
3585 via_cow.as_ref(),
3586 via_string.as_str(),
3587 "From<CaixaDialeto> for Cow<'static, str> and \
3588 From<CaixaDialeto> for String must resolve \
3589 identically on CaixaDialeto::{variant:?} — \
3590 divergence signals the Cow<'static, str> and String \
3591 return-shape paths have drifted onto different \
3592 emit-sets"
3593 );
3594 let via_to_string: String = variant.to_string();
3595 assert_eq!(
3596 via_cow.as_ref(),
3597 via_to_string.as_str(),
3598 "From<CaixaDialeto> for Cow<'static, str> must \
3599 byte-equal CaixaDialeto::to_string on \
3600 CaixaDialeto::{variant:?} — divergence signals the \
3601 trait-idiomatic Cow<'static, str> forward-projection \
3602 axis and the ToString-through-Display axis have \
3603 drifted onto different emit-sets"
3604 );
3605 }
3606 let via_iter: Vec<std::borrow::Cow<'static, str>> = CaixaDialeto::ALL
3607 .iter()
3608 .copied()
3609 .map(std::borrow::Cow::from)
3610 .collect();
3611 let via_method: Vec<std::borrow::Cow<'static, str>> = CaixaDialeto::ALL
3612 .iter()
3613 .map(|d| std::borrow::Cow::Borrowed(d.as_str()))
3614 .collect();
3615 assert_eq!(
3616 via_iter, via_method,
3617 "`.iter().copied().map(Cow::from)` over \
3618 CaixaDialeto::ALL must byte-equal `.iter().map(|d| \
3619 Cow::Borrowed(d.as_str()))` on every arm — the \
3620 trait-idiomatic `From<CaixaDialeto> for Cow<'static, \
3621 str>` axis is what makes the `Cow::from` composition \
3622 route through the substrate-primitive \
3623 CaixaDialeto::as_str accessor rather than a per-call-\
3624 site open-code"
3625 );
3626 for cow in &via_iter {
3627 assert!(
3628 matches!(cow, std::borrow::Cow::Borrowed(_)),
3629 "`.iter().copied().map(Cow::from)` over \
3630 CaixaDialeto::ALL must land on the zero-alloc \
3631 Cow::Borrowed arm on every element — a Cow::Owned \
3632 outcome signals the pipe has silently allocated \
3633 where the substrate-primitive \
3634 CaixaDialeto::as_str `&'static str` return makes \
3635 the borrowed arm the type-correct projection"
3636 );
3637 }
3638 for &variant in CaixaDialeto::ALL {
3639 let via_cow: std::borrow::Cow<'static, str> =
3640 <std::borrow::Cow<'static, str> as From<CaixaDialeto>>::from(variant);
3641 let re_parsed: Result<CaixaDialeto, ()> =
3642 <CaixaDialeto as TryFrom<&str>>::try_from(via_cow.as_ref());
3643 assert_eq!(
3644 re_parsed,
3645 Ok(variant),
3646 "trait-idiomatic Cow<'static, str> forward-projection \
3647 + reverse-projection axis pair must round-trip \
3648 CaixaDialeto::{variant:?} through `.into::<Cow<\
3649 'static, str>>()` on the owned-input surface and \
3650 back through `TryFrom<&str>` on the projection's \
3651 Cow::as_ref borrow — a break signals the \
3652 Cow<'static, str> forward-emit and reverse-parse \
3653 axes have drifted onto different vocabularies \
3654 (unlike the peer CaixaKind axis pair, CaixaDialeto's \
3655 forward emit and reverse parse share one PascalCase \
3656 vocabulary by construction, so the round-trip \
3657 composes directly)"
3658 );
3659 }
3660 }
3661
3662 #[test]
3663 fn caixa_dialeto_from_borrowed_into_static_cow_str_routes_through_as_str_accessor() {
3664 // Fail-before-pass-after byte-parity pin on the newly lifted
3665 // `impl From<&CaixaDialeto> for std::borrow::Cow<'static,
3666 // str>` — asserts the borrowed-input standard-library trait
3667 // impl and the substrate-primitive
3668 // [`super::CaixaDialeto::as_str`] `pub const fn` accessor
3669 // resolve to the same four-arm PascalCase emit-set across
3670 // every arm the exhaustive [`super::CaixaDialeto::ALL`] slice
3671 // enumerates. Rust's standard library does not carry a blanket
3672 // `impl<T: AsRef<str>> From<&T> for Cow<'static, str>` (nor a
3673 // `Copy`-based `impl<T: Copy, U: From<T>> From<&T> for U`), so
3674 // the borrowed-input `Cow<'static, str>` forward-projection
3675 // axis is a distinct trait-idiomatic surface that a
3676 // `let key: Cow<'static, str> = (&dialeto).into();`-shaped
3677 // call site or a `CaixaDialeto::ALL.iter().map(Cow::from)`-
3678 // shaped pipe reaches through this impl and no other — the
3679 // paired owned-input `From<CaixaDialeto> for Cow<'static, str>`
3680 // impl (8322511) forces every borrowed-input call site
3681 // through an explicit `Copy` deref (`Cow::from(*dialeto)`) or
3682 // a `Cow::Borrowed(dialeto.as_str())` open-code whose type
3683 // bounds have no compile-time link back to the substrate
3684 // primitive.
3685 //
3686 // Also asserts the projection lands on the zero-alloc
3687 // [`std::borrow::Cow::Borrowed`] arm (not the
3688 // [`std::borrow::Cow::Owned`] arm) — the substrate-primitive
3689 // [`super::CaixaDialeto::as_str`] accessor's `&'static str`
3690 // return lifetime by construction makes the borrowed arm the
3691 // type-correct projection with no runtime allocation on the
3692 // borrowed-input surface just as on the paired owned-input
3693 // surface.
3694 //
3695 // Closes the `{Self, &Self}` input-shape corner on the
3696 // outside-M3 caixa-core dialect-classification
3697 // [`Cow<'static, str>`] axis on the second outside-M3
3698 // caixa-core closed-set fieldless typed enum peer on the
3699 // caixa surface, exactly as 702cdf4 closed it on the first
3700 // outside-M3 caixa-core peer ([`crate::dep::DepList`]) one
3701 // commit after the owning half (6858bac) landed, as afdf0f4
3702 // closed it on the second M3-mesh-primitive peer
3703 // ([`crate::aplicacao::PlacementStrategy`]) one commit after
3704 // the owning half (eee504d) landed, as 25690ef closed it on
3705 // the first M3-mesh-primitive peer
3706 // ([`crate::aplicacao::WitShape`]) one commit after the
3707 // owning half (8634dec) landed, as d45c409 closed it on the
3708 // top-level [`crate::CaixaKind`] one commit after the owning
3709 // half (99c1735) landed, and as 9b3e4b3 / ee577fd closed it
3710 // on the M2 OTP-shape [`crate::supervisor::RestartStrategy`]
3711 // / [`crate::supervisor::RestartPolicy`] sibling peers one
3712 // commit after (7dd28b3 / 0612398) landed.
3713 for &variant in CaixaDialeto::ALL {
3714 let via_trait: std::borrow::Cow<'static, str> =
3715 <std::borrow::Cow<'static, str> as From<&CaixaDialeto>>::from(&variant);
3716 let via_method: &'static str = variant.as_str();
3717 assert_eq!(
3718 via_trait.as_ref(),
3719 via_method,
3720 "From<&CaixaDialeto> for Cow<'static, str> impl must \
3721 round-trip &CaixaDialeto::{variant:?} to the same \
3722 PascalCase byte-string CaixaDialeto::as_str returns \
3723 — divergence signals a silent detour off the \
3724 substrate-primitive accessor"
3725 );
3726 assert!(
3727 matches!(via_trait, std::borrow::Cow::Borrowed(_)),
3728 "From<&CaixaDialeto> for Cow<'static, str> impl must \
3729 land on the zero-alloc Cow::Borrowed arm on \
3730 &CaixaDialeto::{variant:?} — a Cow::Owned outcome \
3731 signals the projection has silently allocated where \
3732 the substrate-primitive CaixaDialeto::as_str \
3733 `&'static str` return makes the borrowed arm the \
3734 type-correct projection"
3735 );
3736 let via_into: std::borrow::Cow<'static, str> = (&variant).into();
3737 assert_eq!(
3738 via_into.as_ref(),
3739 via_method,
3740 "Into<Cow<'static, str>>::into on \
3741 &CaixaDialeto::{variant:?} must byte-equal \
3742 CaixaDialeto::as_str on the same input — the \
3743 blanket-derived Into shape on the borrowed-input \
3744 surface must resolve to the same as_str dispatch as \
3745 the explicit From impl"
3746 );
3747 assert!(
3748 matches!(via_into, std::borrow::Cow::Borrowed(_)),
3749 "Into<Cow<'static, str>>::into on \
3750 &CaixaDialeto::{variant:?} must land on the \
3751 zero-alloc Cow::Borrowed arm — the blanket-derived \
3752 Into shape on the borrowed-input surface must \
3753 resolve to the same Cow::Borrowed dispatch as the \
3754 explicit From impl"
3755 );
3756 }
3757 }
3758
3759 #[test]
3760 #[allow(
3761 clippy::too_many_lines,
3762 reason = "cross-axis partition pin folds four return-shape paths \
3763 (borrowed-input Cow<'static, str>, owned-input Cow<'static, str>, \
3764 borrowed-input &'static str, borrowed-input String) plus the \
3765 ToString-through-Display witness plus a `.iter().map(Cow::from)` \
3766 pipe witness with zero-alloc discriminator plus a direct \
3767 round-trip witness through TryFrom<&str> over four typed \
3768 variants; the linear per-axis repetition is exactly what the \
3769 fold is pinning — a helper would hide the shape it locks"
3770 )]
3771 fn caixa_dialeto_from_borrowed_into_static_cow_str_agrees_with_paired_axes_on_every_arm() {
3772 // Cross-axis partition pin: the newly lifted trait-idiomatic
3773 // borrowed-input `From<&CaixaDialeto> for
3774 // std::borrow::Cow<'static, str>` (this lift), the paired
3775 // owned-input `From<CaixaDialeto> for
3776 // std::borrow::Cow<'static, str>`, the paired borrowed-input
3777 // `From<&CaixaDialeto> for &'static str`, and the paired
3778 // borrowed-input `From<&CaixaDialeto> for String` forward
3779 // projections must resolve identically on every arm, locking
3780 // the four return-shape paths together by construction so any
3781 // future detour trips at caixa-core test time. Also
3782 // byte-parity witness against the sibling
3783 // [`ToString::to_string`] surface routed through
3784 // [`std::fmt::Display`].
3785 //
3786 // Then a `.iter().map(std::borrow::Cow::from)` pipe witness
3787 // over [`super::CaixaDialeto::ALL`] — whose iterator yields
3788 // `&CaixaDialeto` by construction, so the borrowed-input
3789 // [`std::borrow::Cow<'static, str>`] axis is what routes the
3790 // pipe through the substrate-primitive
3791 // [`super::CaixaDialeto::as_str`] accessor with the zero-alloc
3792 // [`std::borrow::Cow::Borrowed`] arm and without a spurious
3793 // [`Copy`] deref. Every collected element satisfies the
3794 // [`std::borrow::Cow::Borrowed`]-arm predicate so a future
3795 // accidental silent-allocation regression on the pipe's
3796 // iteration axis is a caixa-core-test-time failure.
3797 //
3798 // Then a direct round-trip witness through [`TryFrom<&str>`]
3799 // on the projection's [`std::borrow::Cow::as_ref`] borrow —
3800 // unlike the peer [`crate::CaixaKind`] axis pair (whose
3801 // forward emit lands on the lowercase Portuguese diagnostic
3802 // vocabulary while the reverse parse lands on the
3803 // `PascalCase` wire vocabulary, forcing the round-trip
3804 // through an intermediate [`crate::CaixaKind::wire_name`]
3805 // hop), [`super::CaixaDialeto`]'s forward emit and reverse
3806 // parse share one `PascalCase` vocabulary by construction, so
3807 // the borrowed-input [`std::borrow::Cow<'static, str>`]
3808 // projection composes directly with the trait-idiomatic
3809 // reverse [`TryFrom<&str>`] axis without the wire-vocab
3810 // intermediate hop.
3811 for &variant in CaixaDialeto::ALL {
3812 let via_borrowed_cow: std::borrow::Cow<'static, str> =
3813 <std::borrow::Cow<'static, str> as From<&CaixaDialeto>>::from(&variant);
3814 let via_owned_cow: std::borrow::Cow<'static, str> =
3815 <std::borrow::Cow<'static, str> as From<CaixaDialeto>>::from(variant);
3816 let via_borrowed_static: &'static str =
3817 <&'static str as From<&CaixaDialeto>>::from(&variant);
3818 let via_borrowed_string: String = <String as From<&CaixaDialeto>>::from(&variant);
3819 assert_eq!(
3820 via_borrowed_cow.as_ref(),
3821 via_owned_cow.as_ref(),
3822 "From<&CaixaDialeto> for Cow<'static, str> and \
3823 From<CaixaDialeto> for Cow<'static, str> must \
3824 resolve identically on CaixaDialeto::{variant:?} — \
3825 divergence signals the borrowed-input and \
3826 owned-input Cow<'static, str> return-shape paths \
3827 have drifted onto different emit-sets"
3828 );
3829 assert_eq!(
3830 via_borrowed_cow.as_ref(),
3831 via_borrowed_static,
3832 "From<&CaixaDialeto> for Cow<'static, str> and \
3833 From<&CaixaDialeto> for &'static str must resolve \
3834 identically on CaixaDialeto::{variant:?} — \
3835 divergence signals the borrowed-input Cow<'static, \
3836 str> and borrowed-input &'static str return-shape \
3837 paths have drifted onto different emit-sets"
3838 );
3839 assert_eq!(
3840 via_borrowed_cow.as_ref(),
3841 via_borrowed_string.as_str(),
3842 "From<&CaixaDialeto> for Cow<'static, str> and \
3843 From<&CaixaDialeto> for String must resolve \
3844 identically on CaixaDialeto::{variant:?} — \
3845 divergence signals the borrowed-input Cow<'static, \
3846 str> and borrowed-input String return-shape paths \
3847 have drifted onto different emit-sets"
3848 );
3849 let via_to_string: String = variant.to_string();
3850 assert_eq!(
3851 via_borrowed_cow.as_ref(),
3852 via_to_string.as_str(),
3853 "From<&CaixaDialeto> for Cow<'static, str> must \
3854 byte-equal CaixaDialeto::to_string on \
3855 CaixaDialeto::{variant:?} — divergence signals the \
3856 borrowed-input Cow<'static, str> forward-projection \
3857 axis and the ToString-through-Display axis have \
3858 drifted onto different emit-sets"
3859 );
3860 }
3861 let via_iter: Vec<std::borrow::Cow<'static, str>> = CaixaDialeto::ALL
3862 .iter()
3863 .map(std::borrow::Cow::from)
3864 .collect();
3865 let via_method: Vec<std::borrow::Cow<'static, str>> = CaixaDialeto::ALL
3866 .iter()
3867 .map(|d| std::borrow::Cow::Borrowed(d.as_str()))
3868 .collect();
3869 assert_eq!(
3870 via_iter, via_method,
3871 "`.iter().map(Cow::from)` over CaixaDialeto::ALL must \
3872 byte-equal `.iter().map(|d| Cow::Borrowed(d.as_str()))` \
3873 on every arm — the trait-idiomatic `From<&CaixaDialeto> \
3874 for Cow<'static, str>` axis is what makes the \
3875 `Cow::from` composition on the borrowed-iteration axis \
3876 route through the substrate-primitive \
3877 CaixaDialeto::as_str accessor without a spurious Copy \
3878 deref"
3879 );
3880 for cow in &via_iter {
3881 assert!(
3882 matches!(cow, std::borrow::Cow::Borrowed(_)),
3883 "`.iter().map(Cow::from)` over CaixaDialeto::ALL \
3884 must land on the zero-alloc Cow::Borrowed arm on \
3885 every element — a Cow::Owned outcome signals the \
3886 borrowed-iteration pipe has silently allocated \
3887 where the substrate-primitive CaixaDialeto::as_str \
3888 `&'static str` return makes the borrowed arm the \
3889 type-correct projection"
3890 );
3891 }
3892 for &variant in CaixaDialeto::ALL {
3893 let via_cow: std::borrow::Cow<'static, str> =
3894 <std::borrow::Cow<'static, str> as From<&CaixaDialeto>>::from(&variant);
3895 let re_parsed: Result<CaixaDialeto, ()> =
3896 <CaixaDialeto as TryFrom<&str>>::try_from(via_cow.as_ref());
3897 assert_eq!(
3898 re_parsed,
3899 Ok(variant),
3900 "trait-idiomatic borrowed-input Cow<'static, str> \
3901 forward-projection + reverse-projection axis pair \
3902 must round-trip &CaixaDialeto::{variant:?} through \
3903 `.into::<Cow<'static, str>>()` on the borrowed-input \
3904 surface and back through `TryFrom<&str>` on the \
3905 projection's Cow::as_ref borrow — a break signals \
3906 the borrowed-input Cow<'static, str> forward-emit \
3907 and reverse-parse axes have drifted onto different \
3908 vocabularies (unlike the peer CaixaKind axis pair, \
3909 CaixaDialeto's forward emit and reverse parse share \
3910 one PascalCase vocabulary by construction, so the \
3911 round-trip composes directly)"
3912 );
3913 }
3914 }
3915
3916 #[test]
3917 fn caixa_dialeto_from_into_box_str_routes_through_as_str_accessor() {
3918 // Fail-before-pass-after byte-parity pin on the newly lifted
3919 // `impl From<CaixaDialeto> for Box<str>` — asserts the owned-
3920 // input standard-library trait impl and the substrate-primitive
3921 // [`super::CaixaDialeto::as_str`] `pub const fn` accessor
3922 // resolve to the same four-arm PascalCase emit-set across every
3923 // arm the exhaustive [`super::CaixaDialeto::ALL`] slice
3924 // enumerates. Extends the caixa-core-internal tier of the
3925 // substrate-wide [`Box<str>`] forward-projection campaign onto
3926 // the third caixa-core-internal peer, after the render-side
3927 // path-shape-diagnostic
3928 // [`super::super::render::PathShapeViolation`] pair (0d87a72,
3929 // both corners in one axis) opened the tier and the outside-M3
3930 // caixa-core two-list dep-graph [`super::super::dep::DepList`]
3931 // pair (4aada99, both corners in one axis) extended it. Rust's
3932 // standard library carries `impl From<&str> for Box<str>` and
3933 // `impl From<String> for Box<str>` but no blanket
3934 // `impl<T: AsRef<str>> From<T> for Box<str>`, so this axis is a
3935 // distinct trait-idiomatic surface that a
3936 // `let key: Box<str> = dialeto.into();`-shaped call site reaches
3937 // through this impl and no other — a paired
3938 // `Box::from(dialeto.as_str())` open-code has no compile-time
3939 // link back to the substrate primitive.
3940 for &variant in CaixaDialeto::ALL {
3941 let via_trait: Box<str> = <Box<str> as From<CaixaDialeto>>::from(variant);
3942 let via_method: &'static str = variant.as_str();
3943 assert_eq!(
3944 via_trait.as_ref(),
3945 via_method,
3946 "From<CaixaDialeto> for Box<str> impl must round-trip \
3947 CaixaDialeto::{variant:?} to the same PascalCase \
3948 byte-string CaixaDialeto::as_str returns — divergence \
3949 signals a silent detour off the substrate-primitive \
3950 accessor"
3951 );
3952 let via_into: Box<str> = variant.into();
3953 assert_eq!(
3954 via_into.as_ref(),
3955 via_method,
3956 "Into<Box<str>>::into on CaixaDialeto::{variant:?} must \
3957 byte-equal CaixaDialeto::as_str on the same input — \
3958 the blanket-derived Into shape must resolve to the \
3959 same as_str dispatch as the explicit From impl"
3960 );
3961 }
3962 }
3963
3964 #[test]
3965 fn caixa_dialeto_from_borrowed_into_box_str_routes_through_as_str_accessor() {
3966 // Fail-before-pass-after byte-parity pin on the newly lifted
3967 // `impl From<&CaixaDialeto> for Box<str>` — asserts the
3968 // borrowed-input standard-library trait impl and the substrate-
3969 // primitive [`super::CaixaDialeto::as_str`] `pub const fn`
3970 // accessor resolve to the same four-arm PascalCase emit-set
3971 // across every arm the exhaustive [`super::CaixaDialeto::ALL`]
3972 // slice enumerates. Rust's standard library carries
3973 // `impl From<&str> for Box<str>` and `impl From<String> for
3974 // Box<str>` but no blanket
3975 // `impl<T: AsRef<str>> From<&T> for Box<str>` (nor a `Copy`-
3976 // based `impl<T: Copy, U: From<T>> From<&T> for U`), so the
3977 // borrowed-input [`Box<str>`] forward-projection axis is a
3978 // distinct trait-idiomatic surface that a
3979 // `CaixaDialeto::ALL.iter().map(Box::<str>::from)`-shaped pipe
3980 // (whose iterator over `&'static [CaixaDialeto]` yields
3981 // `&CaixaDialeto` by construction) or a
3982 // `let key: Box<str> = (&dialeto).into();`-shaped call site
3983 // reaches through this impl and no other — the paired owned-
3984 // input `From<CaixaDialeto> for Box<str>` impl alone would
3985 // force every borrowed-input call site through an explicit
3986 // `Copy` deref (`Box::<str>::from(*dialeto)`) or a
3987 // `Box::<str>::from(dialeto.as_str())` open-code whose type
3988 // bounds have no compile-time link back to the substrate
3989 // primitive.
3990 //
3991 // Closes the `{Self, &Self}` input-shape corner on the third
3992 // caixa-core-internal closed-set fieldless typed enum peer of
3993 // the substrate-wide [`Box<str>`] forward-projection campaign,
3994 // matching the trajectory the paired render-side path-shape-
3995 // diagnostic [`super::super::render::PathShapeViolation`] pair
3996 // (0d87a72, both corners in one axis) and the paired outside-M3
3997 // caixa-core two-list dep-graph [`super::super::dep::DepList`]
3998 // pair (4aada99, both corners in one axis) walked before it.
3999 for &variant in CaixaDialeto::ALL {
4000 let via_trait: Box<str> = <Box<str> as From<&CaixaDialeto>>::from(&variant);
4001 let via_method: &'static str = variant.as_str();
4002 assert_eq!(
4003 via_trait.as_ref(),
4004 via_method,
4005 "From<&CaixaDialeto> for Box<str> impl must round-trip \
4006 &CaixaDialeto::{variant:?} to the same PascalCase \
4007 byte-string CaixaDialeto::as_str returns — divergence \
4008 signals a silent detour off the substrate-primitive \
4009 accessor"
4010 );
4011 let via_into: Box<str> = (&variant).into();
4012 assert_eq!(
4013 via_into.as_ref(),
4014 via_method,
4015 "Into<Box<str>>::into on &CaixaDialeto::{variant:?} \
4016 must byte-equal CaixaDialeto::as_str on the same \
4017 input — the blanket-derived Into shape on the \
4018 borrowed-input surface must resolve to the same \
4019 as_str dispatch as the explicit From impl"
4020 );
4021 }
4022
4023 // Pipe witness — the distinguishing shape that forces the
4024 // borrowed-input axis to be independent of the owned-input
4025 // peer. `CaixaDialeto::ALL.iter()` yields `&CaixaDialeto` by
4026 // construction, so `.map(Box::<str>::from)` resolves through
4027 // the borrowed-input `From<&CaixaDialeto> for Box<str>` impl
4028 // and no other — without this axis, the same pipe would force
4029 // an explicit `.copied()` restatement whose type bounds bypass
4030 // the substrate primitive.
4031 let via_pipe: Vec<Box<str>> = CaixaDialeto::ALL.iter().map(Box::<str>::from).collect();
4032 let via_accessor: Vec<&'static str> =
4033 CaixaDialeto::ALL.iter().map(|d| d.as_str()).collect();
4034 assert_eq!(
4035 via_pipe.len(),
4036 via_accessor.len(),
4037 "CaixaDialeto::ALL.iter().map(Box::<str>::from) pipe must \
4038 preserve arity against the paired CaixaDialeto::as_str \
4039 accessor — a length divergence signals the borrowed-input \
4040 axis has silently rejected an arm"
4041 );
4042 for (pipe_arm, accessor_arm) in via_pipe.iter().zip(via_accessor.iter()) {
4043 assert_eq!(
4044 pipe_arm.as_ref(),
4045 *accessor_arm,
4046 "CaixaDialeto::ALL.iter().map(Box::<str>::from) pipe \
4047 must byte-equal the paired \
4048 CaixaDialeto::ALL.iter().map(|d| d.as_str()) pipe on \
4049 every arm — divergence signals the borrowed-input \
4050 `From<&CaixaDialeto> for Box<str>` axis has silently \
4051 detoured off the substrate-primitive accessor"
4052 );
4053 }
4054 }
4055
4056 #[test]
4057 fn caixa_dialeto_from_into_arc_str_routes_through_as_str_accessor() {
4058 // Fail-before-pass-after byte-parity pin on the newly lifted
4059 // `impl From<CaixaDialeto> for std::sync::Arc<str>` — asserts the
4060 // owned-input standard-library trait impl and the substrate-
4061 // primitive [`super::CaixaDialeto::as_str`] `pub const fn` accessor
4062 // resolve to the same four-arm PascalCase emit-set across every
4063 // arm the exhaustive [`super::CaixaDialeto::ALL`] slice enumerates.
4064 // Extends the caixa-core-internal tier of the substrate-wide
4065 // [`std::sync::Arc<str>`] forward-projection campaign onto the
4066 // third caixa-core-internal peer, after the structurally most
4067 // fundamental [`super::super::CaixaKind`] pair (c17be64, both
4068 // corners in one axis) opened the tier and the outside-M3 two-list
4069 // dep-graph [`super::super::dep::DepList`] pair (d8a4652, both
4070 // corners in one axis) extended it. Rust's standard library
4071 // carries `impl From<&str> for std::sync::Arc<str>` and
4072 // `impl From<String> for std::sync::Arc<str>` but no blanket
4073 // `impl<T: AsRef<str>> From<T> for std::sync::Arc<str>` (nor an
4074 // `impl<T: fmt::Display> From<T> for std::sync::Arc<str>`), so
4075 // this axis is a distinct trait-idiomatic surface that a
4076 // `let key: std::sync::Arc<str> = dialeto.into();`-shaped call
4077 // site reaches through this impl and no other — a paired
4078 // `std::sync::Arc::<str>::from(dialeto.as_str())` open-code has no
4079 // compile-time link back to the substrate primitive, and a two-
4080 // step `std::sync::Arc::<str>::from(String::from(dialeto))`
4081 // composition through the owned-`String` axis allocates twice
4082 // where the single-step trait impl allocates once.
4083 //
4084 // Cross-axis byte-parity witness against the sibling owned-input
4085 // `{&'static str, String, Cow<'static, str>, Box<str>}` return-
4086 // shape axes — locking the five return-shape paths on the owned-
4087 // input surface together by construction so any future detour off
4088 // the substrate-primitive [`super::CaixaDialeto::as_str`] accessor
4089 // trips at caixa-core test time.
4090 for &variant in CaixaDialeto::ALL {
4091 let via_trait: std::sync::Arc<str> =
4092 <std::sync::Arc<str> as From<CaixaDialeto>>::from(variant);
4093 let via_method: &'static str = variant.as_str();
4094 assert_eq!(
4095 via_trait.as_ref(),
4096 via_method,
4097 "From<CaixaDialeto> for std::sync::Arc<str> impl must \
4098 round-trip CaixaDialeto::{variant:?} to the same \
4099 PascalCase byte-string CaixaDialeto::as_str returns — \
4100 divergence signals a silent detour off the substrate-\
4101 primitive accessor"
4102 );
4103 let via_into: std::sync::Arc<str> = variant.into();
4104 assert_eq!(
4105 via_into.as_ref(),
4106 via_method,
4107 "Into<std::sync::Arc<str>>::into on CaixaDialeto::\
4108 {variant:?} must byte-equal CaixaDialeto::as_str on the \
4109 same input — the blanket-derived Into shape must resolve \
4110 to the same as_str dispatch as the explicit From impl"
4111 );
4112 let owned_static: &'static str = <&'static str as From<CaixaDialeto>>::from(variant);
4113 assert_eq!(
4114 via_trait.as_ref(),
4115 owned_static,
4116 "From<CaixaDialeto> for std::sync::Arc<str> and \
4117 From<CaixaDialeto> for &'static str must resolve \
4118 identically on CaixaDialeto::{variant:?} — divergence \
4119 signals the owned-input std::sync::Arc<str> and \
4120 &'static str return-shape paths have drifted onto \
4121 different emit-sets"
4122 );
4123 let owned_string: String = <String as From<CaixaDialeto>>::from(variant);
4124 assert_eq!(
4125 via_trait.as_ref(),
4126 owned_string.as_str(),
4127 "From<CaixaDialeto> for std::sync::Arc<str> and \
4128 From<CaixaDialeto> for String must resolve identically \
4129 on CaixaDialeto::{variant:?} — divergence signals the \
4130 owned-input std::sync::Arc<str> and owned-`String` \
4131 return-shape paths have drifted onto different emit-sets"
4132 );
4133 let owned_cow: std::borrow::Cow<'static, str> =
4134 <std::borrow::Cow<'static, str> as From<CaixaDialeto>>::from(variant);
4135 assert_eq!(
4136 via_trait.as_ref(),
4137 owned_cow.as_ref(),
4138 "From<CaixaDialeto> for std::sync::Arc<str> and \
4139 From<CaixaDialeto> for Cow<'static, str> must resolve \
4140 identically on CaixaDialeto::{variant:?} — divergence \
4141 signals the owned-input std::sync::Arc<str> and \
4142 Cow<'static, str> return-shape paths have drifted onto \
4143 different emit-sets"
4144 );
4145 let owned_box: Box<str> = <Box<str> as From<CaixaDialeto>>::from(variant);
4146 assert_eq!(
4147 via_trait.as_ref(),
4148 owned_box.as_ref(),
4149 "From<CaixaDialeto> for std::sync::Arc<str> and \
4150 From<CaixaDialeto> for Box<str> must resolve identically \
4151 on CaixaDialeto::{variant:?} — divergence signals the \
4152 owned-input std::sync::Arc<str> and Box<str> return-\
4153 shape paths have drifted onto different emit-sets"
4154 );
4155 }
4156 }
4157
4158 #[test]
4159 #[allow(
4160 clippy::too_many_lines,
4161 reason = "cross-axis partition pin folds four borrowed-input \
4162 return-shape paths (&'static str, String, Cow<'static, \
4163 str>, Box<str>) plus the paired owned-input Arc<str> \
4164 witness and the .iter().map(std::sync::Arc::<str>::from) \
4165 pipe witness into one exhaustive round-trip over \
4166 CaixaDialeto::ALL — the accepted line-count cost of \
4167 keying the whole borrowed-input Arc<str> corner to the \
4168 substrate-primitive as_str accessor at the same test-site"
4169 )]
4170 fn caixa_dialeto_from_borrowed_into_arc_str_routes_through_as_str_accessor() {
4171 // Fail-before-pass-after byte-parity pin on the newly lifted
4172 // `impl From<&CaixaDialeto> for std::sync::Arc<str>` — asserts the
4173 // borrowed-input standard-library trait impl and the substrate-
4174 // primitive [`super::CaixaDialeto::as_str`] `pub const fn` accessor
4175 // resolve to the same four-arm PascalCase emit-set across every
4176 // arm the exhaustive [`super::CaixaDialeto::ALL`] slice enumerates.
4177 // Rust's standard library does not carry a blanket
4178 // `impl<T: AsRef<str>> From<&T> for std::sync::Arc<str>` (nor a
4179 // `Copy`-based `impl<T: Copy, U: From<T>> From<&T> for U`), so
4180 // the borrowed-input `std::sync::Arc<str>` forward-projection axis
4181 // is a distinct trait-idiomatic surface that a
4182 // `let key: std::sync::Arc<str> = (&dialeto).into();`-shaped call
4183 // site or a
4184 // `CaixaDialeto::ALL.iter().map(std::sync::Arc::<str>::from)`-shaped
4185 // pipe reaches through this impl and no other — the paired owned-
4186 // input `From<CaixaDialeto> for std::sync::Arc<str>` impl alone
4187 // forces every borrowed-input call site through a spurious `Copy`
4188 // deref (`std::sync::Arc::<str>::from((*dialeto).as_str())`) or a
4189 // `.copied()` restatement whose type bounds have no compile-time
4190 // link back to the substrate primitive.
4191 //
4192 // Closes the `{Self, &Self}` input-shape corner on the caixa-
4193 // core-internal tier of the substrate-wide trait-idiomatic
4194 // [`std::sync::Arc<str>`] forward-projection campaign for the
4195 // third caixa-core-internal enum peer, matching the
4196 // `{Self, &Self} × {&'static str, String, Cow<'static, str>,
4197 // Box<str>}` 2×4 forward-projection matrix the peer projection
4198 // surfaces already close on this same enum.
4199 //
4200 // Cross-axis partition pin against the paired owned-input
4201 // [`From<CaixaDialeto> for std::sync::Arc<str>`] and the sibling
4202 // borrowed-input `{&'static str, String, Cow<'static, str>,
4203 // Box<str>}` return-shape axes — locking the five return-shape ×
4204 // input-shape paths on the borrowed-input surface together by
4205 // construction so any future detour off the substrate-primitive
4206 // accessor trips at caixa-core test time. Then a
4207 // `.iter().map(std::sync::Arc::<str>::from)` pipe witness over
4208 // [`super::CaixaDialeto::ALL`] — whose iterator yields
4209 // `&CaixaDialeto` by construction, so the borrowed-input
4210 // [`std::sync::Arc<str>`] axis is what routes the pipe through the
4211 // substrate-primitive [`super::CaixaDialeto::as_str`] accessor
4212 // without a spurious [`Copy`] deref (which would only be reachable
4213 // through the owned-input
4214 // [`From<CaixaDialeto> for std::sync::Arc<str>`] axis by first
4215 // calling `.copied()` on the iterator).
4216 for &variant in CaixaDialeto::ALL {
4217 let via_trait: std::sync::Arc<str> =
4218 <std::sync::Arc<str> as From<&CaixaDialeto>>::from(&variant);
4219 let via_method: &'static str = variant.as_str();
4220 assert_eq!(
4221 via_trait.as_ref(),
4222 via_method,
4223 "From<&CaixaDialeto> for std::sync::Arc<str> impl must \
4224 round-trip &CaixaDialeto::{variant:?} to the same \
4225 PascalCase byte-string CaixaDialeto::as_str returns — \
4226 divergence signals a silent detour off the substrate-\
4227 primitive accessor"
4228 );
4229 let via_into: std::sync::Arc<str> = (&variant).into();
4230 assert_eq!(
4231 via_into.as_ref(),
4232 via_method,
4233 "Into<std::sync::Arc<str>>::into on &CaixaDialeto::\
4234 {variant:?} must byte-equal CaixaDialeto::as_str on the \
4235 same input — the blanket-derived Into shape on the \
4236 borrowed-input surface must resolve to the same as_str \
4237 dispatch as the explicit From impl"
4238 );
4239 let owned_arc: std::sync::Arc<str> =
4240 <std::sync::Arc<str> as From<CaixaDialeto>>::from(variant);
4241 assert_eq!(
4242 via_trait, owned_arc,
4243 "From<&CaixaDialeto> for std::sync::Arc<str> and \
4244 From<CaixaDialeto> for std::sync::Arc<str> must resolve \
4245 identically on CaixaDialeto::{variant:?} — divergence \
4246 signals the borrowed-input and owned-input \
4247 std::sync::Arc<str> forward-projection input-shape paths \
4248 have drifted onto different emit-sets"
4249 );
4250 let borrowed_static: &'static str =
4251 <&'static str as From<&CaixaDialeto>>::from(&variant);
4252 assert_eq!(
4253 via_trait.as_ref(),
4254 borrowed_static,
4255 "From<&CaixaDialeto> for std::sync::Arc<str> and \
4256 From<&CaixaDialeto> for &'static str must resolve \
4257 identically on CaixaDialeto::{variant:?} — divergence \
4258 signals the borrowed-input std::sync::Arc<str> and \
4259 &'static str return-shape paths have drifted onto \
4260 different emit-sets"
4261 );
4262 let borrowed_string: String = <String as From<&CaixaDialeto>>::from(&variant);
4263 assert_eq!(
4264 via_trait.as_ref(),
4265 borrowed_string.as_str(),
4266 "From<&CaixaDialeto> for std::sync::Arc<str> and \
4267 From<&CaixaDialeto> for String must resolve identically \
4268 on CaixaDialeto::{variant:?} — divergence signals the \
4269 borrowed-input std::sync::Arc<str> and owned-`String` \
4270 return-shape paths have drifted onto different emit-sets"
4271 );
4272 let borrowed_cow: std::borrow::Cow<'static, str> =
4273 <std::borrow::Cow<'static, str> as From<&CaixaDialeto>>::from(&variant);
4274 assert_eq!(
4275 via_trait.as_ref(),
4276 borrowed_cow.as_ref(),
4277 "From<&CaixaDialeto> for std::sync::Arc<str> and \
4278 From<&CaixaDialeto> for Cow<'static, str> must resolve \
4279 identically on CaixaDialeto::{variant:?} — divergence \
4280 signals the borrowed-input std::sync::Arc<str> and \
4281 Cow<'static, str> return-shape paths have drifted onto \
4282 different emit-sets"
4283 );
4284 let borrowed_box: Box<str> = <Box<str> as From<&CaixaDialeto>>::from(&variant);
4285 assert_eq!(
4286 via_trait.as_ref(),
4287 borrowed_box.as_ref(),
4288 "From<&CaixaDialeto> for std::sync::Arc<str> and \
4289 From<&CaixaDialeto> for Box<str> must resolve \
4290 identically on CaixaDialeto::{variant:?} — divergence \
4291 signals the borrowed-input std::sync::Arc<str> and \
4292 Box<str> return-shape paths have drifted onto different \
4293 emit-sets"
4294 );
4295 }
4296 let via_iter: Vec<std::sync::Arc<str>> = CaixaDialeto::ALL
4297 .iter()
4298 .map(std::sync::Arc::<str>::from)
4299 .collect();
4300 let via_method: Vec<std::sync::Arc<str>> = CaixaDialeto::ALL
4301 .iter()
4302 .map(|d| std::sync::Arc::<str>::from(d.as_str()))
4303 .collect();
4304 assert_eq!(
4305 via_iter, via_method,
4306 "`.iter().map(std::sync::Arc::<str>::from)` over \
4307 CaixaDialeto::ALL — a call site whose iteration axis holds \
4308 `&CaixaDialeto` by construction — must byte-equal \
4309 `.iter().map(|d| std::sync::Arc::<str>::from(d.as_str()))` \
4310 on every arm — the borrowed-input std::sync::Arc<str> \
4311 `From<&CaixaDialeto> for std::sync::Arc<str>` axis is what \
4312 makes the `std::sync::Arc::<str>::from` composition route \
4313 through the substrate-primitive `CaixaDialeto::as_str` \
4314 accessor without a spurious `Copy` deref (which would only \
4315 be reachable through the owned-input \
4316 `From<CaixaDialeto> for std::sync::Arc<str>` axis by first \
4317 calling `.copied()` on the iterator)"
4318 );
4319 }
4320}