caixa_core/version.rs
1use std::fmt;
2
3use serde::{Deserialize, Serialize};
4use thiserror::Error;
5
6/// A caixa's pinned version — a thin typed wrapper over a String that parses
7/// as [`semver::Version`] on demand.
8///
9/// Stored as a String at rest so authoring a `caixa.lisp` stays a single
10/// quoted literal. The typed form is reached through [`Self::parse`].
11#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, Hash)]
12#[serde(transparent)]
13pub struct CaixaVersion(pub String);
14
15impl CaixaVersion {
16 /// Parse and validate the wrapped string as semver.
17 pub fn parse(&self) -> Result<semver::Version, VersionError> {
18 semver::Version::parse(&self.0)
19 .map_err(|e| VersionError::semver(self.0.clone(), e.to_string()))
20 }
21
22 /// Borrow the string form.
23 #[must_use]
24 pub const fn as_str(&self) -> &str {
25 self.0.as_str()
26 }
27}
28
29impl fmt::Display for CaixaVersion {
30 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
31 f.write_str(&self.0)
32 }
33}
34
35impl From<String> for CaixaVersion {
36 fn from(s: String) -> Self {
37 Self(s)
38 }
39}
40
41impl From<&str> for CaixaVersion {
42 fn from(s: &str) -> Self {
43 Self(s.to_string())
44 }
45}
46
47/// Substrate-canonical stdlib [`std::str::FromStr`] parse-set entry point on
48/// the [`CaixaVersion`] newtype primitive — closes the canonical
49/// `str::parse::<CaixaVersion>()` axis on the paired [`From<&str> for
50/// CaixaVersion`] / [`From<String> for CaixaVersion`] infallible
51/// forward-projection constructors. Delegates byte-for-byte through the
52/// paired borrowed-input `impl From<&str> for CaixaVersion` immediately
53/// above (which wraps `s.to_string()` into the newtype's inner `String`
54/// slot), so every consumer that reaches [`CaixaVersion`] through the
55/// stdlib `T: FromStr`-bounded parse surface (`str::parse::<CaixaVersion>`,
56/// a `clap::Parser`-derived `#[arg(value_parser)]` on a future `feira
57/// publish --versao <ver>` arg-parse, a `serde_with::DisplayFromStr`
58/// wrapper on the [`crate::Caixa::versao`] field in a downstream typed-YAML
59/// derive, or any generic `fn parse_versao<T: FromStr>(s: &str) -> Result<T,
60/// T::Err>` receiver) routes through the same [`String::to_string`]-shaped
61/// wrap the paired `From<&str>` constructor already exercises. `type Err =
62/// std::convert::Infallible` because the paired `From<&str>` constructor is
63/// total — [`CaixaVersion`] stores the wrapped string raw at rest (the
64/// author surface's single-quoted `:versao "…"` literal round-trips
65/// byte-for-byte) and defers semver validation to the paired
66/// [`CaixaVersion::parse`] `Result<semver::Version, VersionError>`
67/// accessor, so no byte-string the standard-library parse-set entry point
68/// receives can fail construction on this axis (any `&str` is a valid
69/// `CaixaVersion` body at rest; only `.parse::<semver::Version>()` on the
70/// wrapped body can reject a shape the semver grammar refuses). Peer of
71/// the paired `impl FromStr for String` stdlib impl on the standard-library
72/// `String` newtype (whose `Err = Infallible` covers the same "any `&str` is
73/// a valid `String` body" total-wrap discipline the [`CaixaVersion`]
74/// newtype installs on the caixa-core surface). The first standard-library
75/// stdlib-parse-set entry point on the [`CaixaVersion`] newtype beyond the
76/// paired forward-projection [`From<&str>`] / [`From<String>`]
77/// constructors and the sibling [`fmt::Display`] / [`AsRef<str>`] /
78/// [`std::borrow::Borrow<str>`] projections the newtype already carries.
79///
80/// # Compounding
81///
82/// The stdlib parse-set entry point is the canonical Rust-idiomatic axis
83/// generic bounds compose against: `str::parse::<T>()` is a `T: FromStr`-
84/// bounded generic (not a `T: for<'a> TryFrom<&'a str>`-bounded one), so
85/// lifting the axis onto [`CaixaVersion`] unlocks the `.parse::<CaixaVersion>()`
86/// short-form on every future stdlib-shaped consumer without forcing the
87/// caller to spell the paired `From<&str>` constructor at the wire-up site.
88/// A future `clap::Args`-derived `feira publish --versao <ver>` arg-parse
89/// composes `arg.parse::<CaixaVersion>()` directly through the
90/// `#[arg(value_parser = clap::value_parser!(CaixaVersion))]` short-form
91/// (which resolves through the `T: FromStr` bound `clap::value_parser!`
92/// installs on any type carrying the trait), a `serde_with::DisplayFromStr`
93/// wrapper on a future typed-YAML [`crate::Caixa::versao`] field routes
94/// through the same `T: FromStr` bound `serde_with` keys off, and any
95/// generic per-authored-string coalescer over a mixed newtype family
96/// (`Result<T, T::Err>` on a `T: FromStr` bound) picks up
97/// [`CaixaVersion`] as one of its arms by construction.
98///
99/// # Round-trip discipline
100///
101/// The `Err = Infallible` shape witnesses the round-trip discipline the
102/// paired forward-projection [`fmt::Display`] impl closes at compile time:
103/// `s.parse::<CaixaVersion>().unwrap().to_string() == s` for every `&str`
104/// (the fail-before-pass-after pin
105/// [`caixa_version_from_str_round_trips_through_display_on_every_input`]
106/// witnesses this against the sibling `caret_matches_minor_range` /
107/// `star_is_any` / `caixa_version_as_str_accessor_is_const_fn` fixture
108/// bodies covering the semver-shape, prerelease-shape, empty-body,
109/// requirement-shape, and non-semver-junk corners). Any future accidental
110/// narrowing (a stray `parse_semver_first` validation gate slipping onto
111/// the wrap path, a normalization step that would drop whitespace or
112/// canonicalize a prerelease tag) trips the pin at caixa-core build time
113/// under the byte-equality assertion, refusing the divergent shape ahead
114/// of the downstream materializer's admit cycle.
115impl std::str::FromStr for CaixaVersion {
116 type Err = std::convert::Infallible;
117
118 fn from_str(s: &str) -> Result<Self, Self::Err> {
119 // Delegate byte-for-byte through the paired borrowed-input
120 // `impl From<&str> for CaixaVersion` constructor above — the
121 // total-wrap axis every stdlib `T: FromStr`-bounded consumer
122 // reaches [`CaixaVersion`] through resolves to the same
123 // [`String::to_string`]-shaped body the sibling forward-
124 // projection constructor already installs. `type Err =
125 // Infallible` because the paired constructor is total; `Ok`
126 // is the only reachable arm on this axis.
127 Ok(<Self as From<&str>>::from(s))
128 }
129}
130
131/// Substrate-canonical [`AsRef<str>`] projection on the [`CaixaVersion`]
132/// typed newtype — routes through the same [`CaixaVersion::as_str`]
133/// `pub const fn` scalar accessor the sibling [`fmt::Display`] impl
134/// and every downstream `&str`-shaped consumer already keys off, so
135/// any future consumer that binds a [`CaixaVersion`] through the
136/// standard-library `impl AsRef<str>` bound (a `Path`-shaped file-
137/// system reader on the operator side that accepts the version body
138/// as one segment of a per-caixa `versao/<v>/...` on-disk cache path,
139/// a builder-shaped API on the future `feira publish` writer verb
140/// that composes `<prefix><versao>` through a git-tag builder crate's
141/// `impl AsRef<str>` join step, a `HashMap<CaixaVersion, _>` lookup
142/// through the `map.get::<str>(v.as_ref())` shape a future
143/// version-keyed dispatch table lands on) reaches the wrapped
144/// [`String`] through one substrate-primitive dispatch rather than
145/// through the pre-lift `.as_str()` open-coded projection at every
146/// wire-up.
147///
148/// Peer of the sibling [`fmt::Display`] impl on the same primitive —
149/// both delegate to the shared [`CaixaVersion::as_str`] `pub const
150/// fn` accessor, so [`format!("{v}")`], `v.as_str()`, and
151/// `<CaixaVersion as AsRef<str>>::as_ref(&v)` resolve to the same
152/// byte-string per instance by construction. A future rebrand of the
153/// wrapped storage (a hypothetical widening to a typed [`semver::Version`]
154/// slot the roadmap acknowledges once eager parse-on-construct
155/// discipline lands, an internal normalization step that trims
156/// leading zeroes off pre-release identifiers, a per-cluster overlay
157/// the operator pins through a future `:versao-overrides` slot) that
158/// changes what [`CaixaVersion::as_str`] returns migrates every
159/// consumer of every one of the three paths in lockstep.
160///
161/// Same "route the trait impl through the substrate-primitive
162/// accessor" discipline the sibling [`fmt::Display`] impl on this
163/// type already carries — extends it onto the standard-library
164/// [`AsRef<str>`] projection axis every third-party API that takes
165/// `impl AsRef<str>` (the [`std::path::Path::new`] / [`std::fs`]
166/// interop surface, [`std::process::Command::arg`], the peer
167/// `tracing::field::Value` recorder's `Str`-arm, every `clap`-side
168/// `value_parser!` fold that accepts an owned newtype through
169/// `impl AsRef<str>`) already binds through. Rust-side newtype
170/// convention pairs `AsRef<str>` and [`fmt::Display`] on the same
171/// primitive so a caller who has one has both; before this lift,
172/// [`CaixaVersion`] carried [`fmt::Display`] but not the paired
173/// [`AsRef<str>`] impl the convention names.
174///
175/// The first standard-library trait added to [`CaixaVersion`] beyond
176/// the pre-existing [`serde::Serialize`] / [`serde::Deserialize`] /
177/// [`Debug`] / [`Clone`] / [`PartialEq`] / [`Eq`] / [`Hash`] derives
178/// and the paired [`fmt::Display`] / [`From<String>`] / [`From<&str>`]
179/// hand-written impls. Pinned load-bearing by
180/// [`tests::caixa_version_as_ref_str_routes_through_as_str_accessor`]
181/// (byte-parity pin against [`CaixaVersion::as_str`]) — any future
182/// silent detour that routes the impl through a divergent projection
183/// (a `Cow<'_, str>` intermediate, a stray `.to_lowercase()`
184/// normalization, a swap onto a per-arm inline `&self.0.as_str()`
185/// re-inlining) trips at caixa-core test time under `assert_eq!`
186/// rather than at a downstream `impl AsRef<str>`-bound consumer's
187/// silent split.
188impl AsRef<str> for CaixaVersion {
189 fn as_ref(&self) -> &str {
190 self.as_str()
191 }
192}
193
194/// Trait-idiomatic *HashMap-key-shaped* borrow projection on the
195/// [`CaixaVersion`] newtype primitive — the standard-library
196/// [`std::borrow::Borrow<str>`] companion to the paired sibling
197/// [`AsRef<str>`] impl (a086 lift) on the same borrow-projection axis of
198/// this primitive. Routes byte-for-byte through the substrate-primitive
199/// [`CaixaVersion::as_str`] `pub const fn` accessor — the same accessor
200/// the paired [`AsRef<str>`] and [`fmt::Display`] impls already delegate
201/// through — so every consumer that binds a [`CaixaVersion`] through the
202/// standard-library `Borrow<str>` bound reaches the wrapped byte-string
203/// through one substrate-primitive dispatch rather than through a
204/// pre-lift `.as_str()` open-coded projection at every wire-up.
205///
206/// A future consumer that wants to key a map or set by
207/// [`CaixaVersion`] and look up entries by a borrowed [`&str`] — a
208/// per-`:versao` compatibility matrix `HashMap<CaixaVersion, PolicyRow>`
209/// where the reconciliation loop's per-cycle `.get(current_versao_str)`
210/// probes the map with the raw `&str` view of the current cluster
211/// snapshot's version body (the `HashMap::get<Q: ?Sized>` signature is
212/// `where K: Borrow<Q>, Q: Hash + Eq`; without this impl the caller must
213/// wrap the borrowed `&str` in a fresh [`CaixaVersion`] allocation on
214/// every probe), a future `BTreeMap<CaixaVersion, _>::range(..)` sweep
215/// over a per-versao index that accepts a borrowed `&str` range bound
216/// through the same `Borrow<str>` bound, a
217/// `HashSet<CaixaVersion>::contains(&str)` membership probe on a
218/// per-versao denylist keyed by owned [`CaixaVersion`] but queried by
219/// the borrowed view — reaches the wrapped byte-string through this one
220/// dispatch on the substrate primitive, without the pre-lift
221/// `CaixaVersion::from(<&str>)` per-probe allocation the paired forward
222/// [`From<&str> for CaixaVersion`] constructor would otherwise force at
223/// every lookup site.
224///
225/// Peer of the sibling [`AsRef<str>`] impl on the same borrow-projection
226/// axis — both project a borrowed `&self` binding onto a borrowed `&str`
227/// via the shared substrate-primitive [`CaixaVersion::as_str`] accessor.
228/// Rust's standard library deliberately splits the two trait axes on the
229/// two bounds they carry: [`AsRef<str>`] is the *conversion* bound used
230/// by APIs that accept `impl AsRef<str>` and view the input as a `&str`
231/// projection (the [`std::path::Path::new`] / [`std::fs`] interop
232/// surface, [`std::process::Command::arg`], [`clap`]-side
233/// `value_parser!` folds), while [`std::borrow::Borrow<str>`] is the
234/// stricter *identity* bound the collection APIs
235/// ([`std::collections::HashMap`], [`std::collections::BTreeMap`],
236/// [`std::collections::HashSet`], [`std::collections::BTreeSet`]) key
237/// their lookup surfaces off — [`std::borrow::Borrow`] additionally
238/// promises that a borrowed view produced through [`Borrow::borrow`]
239/// hashes and compares byte-identically to the owned form, which is the
240/// contract [`std::collections::HashMap::get`] relies on when it hashes
241/// the query key through `Q` (`str`) and matches against slot keys
242/// hashed through `K` ([`CaixaVersion`]). The [`CaixaVersion`] newtype
243/// meets that contract by construction: the derived [`Hash`] impl hashes
244/// the wrapped [`String`] field, which (through the standard-library
245/// `impl Hash for String { fn hash(...) { (**self).hash(...) } }`
246/// pass-through) dispatches to [`str::hash`] on the raw bytes — the same
247/// dispatch a direct `.hash()` on the `&str` returned by
248/// [`Self::borrow`] would take. The derived [`PartialEq`] and [`Eq`]
249/// impls compare field-wise (byte-equal on the wrapped [`String`]), so
250/// `cv1 == cv2` reduces to `cv1.borrow() == cv2.borrow()` at the
251/// `&str`-projection axis. Both invariants — hash-agrees and
252/// eq-agrees — hold structurally, so this impl is sound under the
253/// [`std::borrow::Borrow`] documented safety contract.
254///
255/// Same "one substrate-primitive dispatch, one shared accessor" discipline
256/// the paired [`AsRef<str>`] impl on this primitive already carries —
257/// extends it onto the [`std::borrow::Borrow<str>`] projection axis the
258/// standard-library collection APIs key their `.get::<Q>` /
259/// `.contains::<Q>` / `.range::<R, T>` / `.remove::<Q>` lookup surfaces
260/// off. Rust's standard library mirrors this exact pairing on its own
261/// [`String`] primitive (`impl AsRef<str> for String` +
262/// `impl Borrow<str> for String`), so a newtype that carries one axis
263/// but not the other splits off the convention that lets every
264/// [`String`]-shaped consumer swap the newtype in without re-shaping
265/// its bounds.
266///
267/// Pinned load-bearing by
268/// [`tests::caixa_version_borrow_str_routes_through_as_str_accessor`]
269/// (byte-parity pin against [`CaixaVersion::as_str`] on the same
270/// instance),
271/// [`tests::caixa_version_borrow_str_and_as_ref_str_agree_on_every_shape`]
272/// (cross-axis partition pin against the paired [`AsRef<str>`] impl,
273/// closing the "borrow-axis two-corner split" bifurcation on the same
274/// wrapped body), and
275/// [`tests::caixa_version_borrow_str_enables_hashmap_lookup_by_borrowed_key`]
276/// (contract-witness pin routing a [`std::collections::HashMap::get`]
277/// probe against a `&str` key through the `Borrow<str>` bound on a map
278/// keyed by owned [`CaixaVersion`], asserting the collection APIs reach
279/// the same slot the borrowed and owned forms compose the same hash for).
280impl std::borrow::Borrow<str> for CaixaVersion {
281 fn borrow(&self) -> &str {
282 self.as_str()
283 }
284}
285
286/// Trait-idiomatic *owned-`String`* reverse projection on the
287/// [`CaixaVersion`] newtype primitive — the owned-heap-string inverse
288/// of the pre-existing [`From<String> for CaixaVersion`] /
289/// [`From<&str> for CaixaVersion`] forward-projection pair on this
290/// primitive. Returns the wrapped [`String`] verbatim ([`Self::0`],
291/// a move of the pre-existing heap allocation — no re-copy of the
292/// per-instance version body's bytes), so every consumer that binds a
293/// [`CaixaVersion`] through the standard-library `.into()` /
294/// [`From<Self> for String`] (equivalently [`Into<String>`]) axis
295/// reaches the wrapped byte-string through one substrate-primitive
296/// dispatch rather than through a `.as_str().to_owned()` /
297/// `.to_string()` allocating detour whose bounds have no compile-time
298/// link back to the newtype's storage.
299///
300/// A future consumer that wants to unwrap a [`CaixaVersion`] into an
301/// owned [`String`] — a `serde_json::Value::String(versao.into())`
302/// structured-payload composer where the `Value::String` arm typing
303/// demands an owned [`String`] and the sibling
304/// [`AsRef<str>`]-borrowed axis forces an explicit `.to_owned()`
305/// restatement at every call site, a future
306/// `HashMap::<String, _>::from_iter([(versao.into(), _)])` per-versao
307/// lookup where the map's key type is owned [`String`] rather than
308/// [`&str`] borrowed from a stashed [`CaixaVersion`], a future
309/// `Cow::<'static, str>::Owned(versao.into())` composer where the
310/// owned arm typing rules out the borrowed [`AsRef<str>`] return —
311/// reaches the wrapped [`String`] through this one dispatch, avoiding
312/// the pre-lift double-allocation (`.as_str().to_owned()` on the owned
313/// path would allocate a fresh [`String`] rather than reuse the
314/// wrapper's own heap allocation).
315///
316/// Opens the trait-idiomatic *owned-`String`* reverse-projection axis
317/// on the substrate's core String-wrapper newtype primitive
318/// [`CaixaVersion`], mirroring the paired owned-`String` forward-
319/// projection family the sibling closed-set fieldless typed enums
320/// ([`crate::supervisor::RestartStrategy`] (7baa18a, first-mover),
321/// [`crate::supervisor::RestartPolicy`] (7851725),
322/// [`crate::CaixaKind`] (per its own doc block, third peer), plus the
323/// remaining twelve closed-set enums) already carry — Rust's standard
324/// library does not derive `From<Self> for String` from `From<String>
325/// for Self`, so every newtype that carries a forward `From<String>`
326/// constructor but not the paired reverse-unwrap axis forces every
327/// call site through a `.to_string()` / `.as_str().to_owned()` detour
328/// that allocates fresh bytes rather than moving the wrapper's own
329/// heap allocation.
330///
331/// Preserves the two-path split on the wrapped byte-string: the paired
332/// [`AsRef<str>`] and [`fmt::Display`] impls stay reachable for the
333/// borrowed `&str` and formatter-output paths, this impl closes the
334/// owned-`String` reverse axis. Same "one dispatch on the substrate
335/// primitive" discipline the peer forward `From<String> for
336/// CaixaVersion` / `From<&str> for CaixaVersion` constructors carry,
337/// now extended onto the owned-heap-string reverse projection.
338///
339/// Pinned load-bearing by
340/// [`tests::caixa_version_from_into_owned_string_returns_wrapped_body`]
341/// (byte-parity pin against [`CaixaVersion::as_str`] on the same
342/// instance) and
343/// [`tests::caixa_version_from_into_owned_string_and_as_str_agree_on_every_shape`]
344/// (cross-axis partition pin against the paired borrowed
345/// [`AsRef<str>`] impl and the sibling [`fmt::Display`]-routed
346/// [`ToString::to_string`] surface, plus a round-trip witness through
347/// the paired forward [`From<String> for CaixaVersion`] constructor
348/// closing the two-way `Self → String → Self` cycle by construction).
349impl From<CaixaVersion> for String {
350 fn from(v: CaixaVersion) -> String {
351 v.0
352 }
353}
354
355/// Trait-idiomatic *borrowed-input, owned-`String` output* reverse
356/// projection on the [`CaixaVersion`] newtype primitive — the
357/// borrowed-input companion to the paired owned-input
358/// [`From<CaixaVersion> for String`] impl immediately above. Routes
359/// byte-for-byte through the substrate-primitive
360/// [`CaixaVersion::as_str`] `pub const fn` accessor (via
361/// [`str::to_owned`]) so every consumer that holds a
362/// borrowed [`&CaixaVersion`] and needs an owned [`String`] — a
363/// `[…].iter().map(String::from).collect::<Vec<_>>()` per-instance
364/// materializer over `&[CaixaVersion]` (whose iterator yields
365/// `&CaixaVersion`, not `CaixaVersion`, so the owned-input
366/// [`From<CaixaVersion> for String`] axis alone forces every call site
367/// through an explicit `.clone()` / dereference restatement), a future
368/// `HashMap::<String, _>::from_iter` that keys off a borrowed-
369/// iteration axis where cloning the wrapper would allocate one
370/// [`String`] beyond the map entry's own, a future
371/// `serde_json::Value::String(String::from(&caixa.versao))`
372/// structured-payload composer that owns the emit-path without moving
373/// out of a borrowed field — reaches the wrapped byte-string through
374/// this one dispatch on the substrate primitive.
375///
376/// Second corner on the `{Self, &Self} → String` reverse-projection
377/// family opened on the paired owned-input
378/// [`From<CaixaVersion> for String`] impl immediately above. Rust's
379/// `From` trait does not derive the `From<&Self>` sibling from a
380/// `From<Self>` impl (the blanket
381/// `impl<T, U> From<&T> for U where T: Clone, U: From<T>` does not
382/// exist in `core`), so every newtype that carries the owned-input
383/// reverse axis but not the borrowed-input axis forces every borrowed
384/// call site through a `.clone()` / `<String>::from(v.clone())` detour
385/// whose type bounds have no compile-time link back to the newtype.
386///
387/// Pinned load-bearing by
388/// [`tests::caixa_version_from_borrowed_into_owned_string_routes_through_as_str_accessor`]
389/// (byte-parity pin against [`CaixaVersion::as_str`] via a borrowed
390/// input) and
391/// [`tests::caixa_version_from_owned_and_borrowed_into_string_agree_on_every_shape`]
392/// (cross-axis partition pin against the paired owned-input
393/// [`From<CaixaVersion> for String`] impl on the same instance,
394/// closing the "owned-input move vs. borrowed-input clone" bifurcation
395/// on the same wrapped body).
396impl From<&CaixaVersion> for String {
397 fn from(v: &CaixaVersion) -> String {
398 v.as_str().to_owned()
399 }
400}
401
402/// Trait-idiomatic *owned-input, [`std::borrow::Cow<'static, str>`]
403/// output* reverse projection on the [`CaixaVersion`] newtype
404/// primitive — the [`Cow<'static, str>`] companion to the paired
405/// owned-input [`From<CaixaVersion> for String`] impl (999a310) on
406/// the same primitive. Routes through
407/// [`std::borrow::Cow::Owned`]`(v.0)`, moving the wrapper's own heap
408/// allocation through verbatim (no re-copy of the per-instance version
409/// body's bytes, no allocating detour through
410/// [`CaixaVersion::as_str`] + [`str::to_owned`]) — so every consumer
411/// that binds a [`CaixaVersion`] through the standard-library `.into()`
412/// / [`From<Self> for Cow<'static, str>`] axis reaches the wrapped
413/// byte-string through one substrate-primitive dispatch on the exact
414/// same heap allocation the manifest-parse forward
415/// [`From<String> for CaixaVersion`] constructor accepted.
416///
417/// A future consumer that wants a [`Cow<'static, str>`]-typed handle
418/// on a [`CaixaVersion`] — a
419/// `metric_label: Cow<'static, str> = versao.into()` structured-log
420/// key on a future per-caixa `caixa-operator` reconciliation counter
421/// (whose emit surface types metric keys as `Cow<'static, str>` so
422/// static compile-time literals and dynamic version bodies share the
423/// same key-slot without an unconditional heap allocation on the
424/// literal path), a future
425/// `HashMap::<Cow<'static, str>, _>::from_iter([(versao.into(), _)])`
426/// per-versao lookup where the map's key type is
427/// [`Cow<'static, str>`] rather than owned [`String`] so
428/// literal-lifetime keys can share the same map without wrapping in an
429/// extra [`String`] allocation, a future M4 admission-webhook
430/// rejection body whose per-arm error message composes through
431/// `format!("{}", Cow::<'static, str>::from(caixa.versao))` where the
432/// [`Cow<'static, str>`] intermediate is what the sibling error-frame
433/// composer accepts — reaches the wrapped byte-string through this
434/// one dispatch, without the pre-lift `.to_string().into()` /
435/// `Cow::Owned(String::from(v))` double-hop that would allocate a
436/// fresh intermediary [`String`] on the way to the same
437/// [`Cow::Owned`] arm.
438///
439/// Deliberately returns [`std::borrow::Cow::Owned`] rather than
440/// [`std::borrow::Cow::Borrowed`] — the substrate-primitive
441/// [`CaixaVersion::as_str`] accessor's return does not carry the
442/// `&'static str` lifetime by construction (the wrapped [`String`]
443/// storage is a runtime heap allocation, not a compile-time literal),
444/// so the [`Cow<'static, str>`] output shape rules out the borrowed
445/// arm and the owned arm is the type-correct projection. Peer of the
446/// paired owned-input [`From<CaixaVersion> for String`] impl on the
447/// same primitive — both route through the wrapper's own heap
448/// allocation via a move on `v.0`, preserving the zero-copy
449/// discipline the substrate opens on its String-wrapper newtype
450/// primitive.
451///
452/// Opens the trait-idiomatic *owned-input, [`Cow<'static, str>`]*
453/// reverse-projection axis on the substrate's core String-wrapper
454/// newtype primitive [`CaixaVersion`], mirroring the paired
455/// [`Cow<'static, str>`] *forward*-projection family the sibling
456/// closed-set fieldless typed enums (via
457/// [`crate::supervisor::RestartStrategy`],
458/// [`crate::supervisor::RestartPolicy`], and the remaining twelve
459/// closed-set enums) already carry — on the enum peers, the paired
460/// axis returns [`Cow::Borrowed`] because the accessor returns
461/// `&'static str`; on this newtype the paired axis returns
462/// [`Cow::Owned`] because the wrapped storage is runtime-allocated.
463/// Rust's standard library does not derive `From<Self> for
464/// Cow<'static, str>` from `From<Self> for String` (nor derive
465/// `From<&Self>` from `From<Self>`), so every newtype that carries a
466/// reverse `From<Self> for String` unwrap axis but not the paired
467/// [`Cow<'static, str>`] axis forces every
468/// [`Cow<'static, str>`]-typed call site through a `.to_string().into()`
469/// double-allocation detour that heap-allocates a fresh intermediary
470/// [`String`] between the wrapper and the [`Cow::Owned`] arm.
471///
472/// Pinned load-bearing by
473/// [`tests::caixa_version_from_into_owned_cow_str_returns_owned_wrapped_body`]
474/// (byte-parity + [`Cow::Owned`]-arm pin against
475/// [`CaixaVersion::as_str`] on the same instance, plus a round-trip
476/// witness through the paired [`From<String> for CaixaVersion`]
477/// constructor) and
478/// [`tests::caixa_version_from_into_owned_cow_str_and_string_agree_on_every_shape`]
479/// (cross-axis partition pin against the paired owned-input
480/// [`From<CaixaVersion> for String`] impl on the same instance,
481/// closing the "owned-input into [`String`] vs. owned-input into
482/// [`Cow<'static, str>`]" bifurcation on the same wrapped body).
483impl From<CaixaVersion> for std::borrow::Cow<'static, str> {
484 fn from(v: CaixaVersion) -> std::borrow::Cow<'static, str> {
485 std::borrow::Cow::Owned(v.0)
486 }
487}
488
489/// Trait-idiomatic *borrowed-input, [`std::borrow::Cow<'static, str>`]
490/// output* reverse projection on the [`CaixaVersion`] newtype
491/// primitive — the borrowed-input companion to the paired owned-input
492/// [`From<CaixaVersion> for std::borrow::Cow<'static, str>`] impl
493/// immediately above. Routes byte-for-byte through the
494/// substrate-primitive [`CaixaVersion::as_str`] `pub const fn`
495/// accessor (via [`str::to_owned`] wrapped in
496/// [`std::borrow::Cow::Owned`]) so every consumer that holds a
497/// borrowed [`&CaixaVersion`] and needs a [`Cow<'static, str>`] —
498/// a `[…].iter().map(Cow::<'static, str>::from).collect::<Vec<_>>()`
499/// per-instance materializer over `&[CaixaVersion]` (whose iterator
500/// yields `&CaixaVersion`, not `CaixaVersion`, so the paired
501/// owned-input [`From<CaixaVersion> for Cow<'static, str>`] axis
502/// alone forces every call site through an explicit `.clone()` /
503/// dereference restatement), a future
504/// `HashMap::<Cow<'static, str>, _>::from_iter` that keys off a
505/// borrowed-iteration axis where cloning the wrapper would allocate
506/// one [`String`] beyond the eventual [`Cow::Owned`] arm's own, a
507/// future generic
508/// `<T: for<'a> Into<Cow<'static, str>>>`-bound emitter on a
509/// per-caixa diagnostic column that walks the
510/// `iter().map(Into::into)` shape verbatim — reaches the wrapped
511/// byte-string through this one dispatch on the substrate primitive.
512///
513/// Deliberately returns [`std::borrow::Cow::Owned`] rather than
514/// [`std::borrow::Cow::Borrowed`] — the substrate-primitive
515/// [`CaixaVersion::as_str`] accessor's return does not carry the
516/// `&'static str` lifetime by construction, so the
517/// [`Cow<'static, str>`] output shape rules out the borrowed arm and
518/// the owned arm is the type-correct projection (mirroring the paired
519/// owned-input impl's own [`Cow::Owned`] discipline). Second corner
520/// on the `{Self, &Self} → Cow<'static, str>` reverse-projection
521/// family opened on the paired owned-input impl immediately above.
522/// Rust's `From` trait does not derive the `From<&Self>` sibling from
523/// a `From<Self>` impl (the blanket
524/// `impl<T, U> From<&T> for U where T: Clone, U: From<T>` does not
525/// exist in `core`), so every newtype that carries the owned-input
526/// reverse [`Cow<'static, str>`] axis but not the borrowed-input axis
527/// forces every borrowed call site through a `.clone()` /
528/// `<Cow<'static, str>>::from(v.clone())` detour whose type bounds
529/// have no compile-time link back to the newtype.
530///
531/// Pinned load-bearing by
532/// [`tests::caixa_version_from_borrowed_into_owned_cow_str_routes_through_as_str_accessor`]
533/// (byte-parity + [`Cow::Owned`]-arm pin against
534/// [`CaixaVersion::as_str`] via a borrowed input, plus a
535/// source-survival witness against silent move-out) and
536/// [`tests::caixa_version_from_owned_and_borrowed_into_cow_str_agree_on_every_shape`]
537/// (cross-axis partition pin against the paired owned-input impl on
538/// the same instance, closing the "owned-input move vs. borrowed-input
539/// clone" bifurcation on the same wrapped body through the
540/// [`Cow<'static, str>`] axis).
541impl From<&CaixaVersion> for std::borrow::Cow<'static, str> {
542 fn from(v: &CaixaVersion) -> std::borrow::Cow<'static, str> {
543 std::borrow::Cow::Owned(v.as_str().to_owned())
544 }
545}
546
547/// Trait-idiomatic *owned-input, [`Box<str>`] output* reverse projection
548/// on the [`CaixaVersion`] newtype primitive — the [`Box<str>`] companion
549/// to the paired owned-input [`From<CaixaVersion> for String`] (999a310)
550/// and [`From<CaixaVersion> for std::borrow::Cow<'static, str>`] (55532e5)
551/// impls on the same primitive. Routes through
552/// [`String::into_boxed_str`]`(v.0)`, shrinking the wrapper's own heap
553/// allocation to a fit-to-length boxed slice — no re-copy of the
554/// per-instance version body's bytes on the fixed-capacity path
555/// (`String::into_boxed_str` reuses the underlying `Vec<u8>` buffer
556/// verbatim when the length matches its capacity; when the [`String`]
557/// carries slack it reallocates once to shrink), so every consumer that
558/// binds a [`CaixaVersion`] through the standard-library `.into()` /
559/// [`From<Self> for Box<str>`] axis reaches the wrapped byte-string
560/// through one substrate-primitive dispatch on the same underlying heap
561/// storage the manifest-parse forward [`From<String> for CaixaVersion`]
562/// constructor accepted.
563///
564/// A future consumer that wants a [`Box<str>`]-typed handle on a
565/// [`CaixaVersion`] — a per-caixa struct field typed `Box<str>` rather
566/// than [`String`] to trim the sixteen-byte length + capacity header
567/// down to eight bytes on the pointer + length pair (a shape the
568/// substrate acknowledges as the natural fixed-length storage for
569/// once-written-never-mutated version strings held across the whole
570/// operator reconciliation cycle), a future
571/// `HashMap::<Box<str>, _>::from_iter([(versao.into(), _)])` per-versao
572/// lookup where the map's key type is [`Box<str>`] rather than owned
573/// [`String`] so the map's per-entry key-slot carries the sixteen-byte
574/// [`Box<str>`] header instead of the twenty-four-byte [`String`]
575/// header, a future M4 admission-webhook rejection body whose per-arm
576/// error-frame composer accepts a [`Box<str>`] intermediate for the
577/// same reason — reaches the wrapped byte-string through this one
578/// dispatch, without the pre-lift `.to_string().into_boxed_str()`
579/// double-hop that would allocate a fresh intermediary [`String`] on
580/// the way to the same [`Box<str>`] slot.
581///
582/// Peer of the paired owned-input [`From<CaixaVersion> for String`]
583/// (999a310) and [`From<CaixaVersion> for Cow<'static, str>`] (55532e5)
584/// impls on the same primitive — all three route through `v.0`
585/// (the [`String`] axis returns the wrapped buffer verbatim; the
586/// [`Cow<'static, str>`] axis wraps it in [`Cow::Owned`]; this axis
587/// shrinks it to a fit-to-length boxed slice via [`String::into_boxed_str`]),
588/// preserving the zero-copy discipline the substrate opens on its
589/// String-wrapper newtype primitive across the three reverse-projection
590/// axes. Rust's standard library does not derive `From<Self> for
591/// Box<str>` from `From<Self> for String` (nor from `From<Self> for
592/// Cow<'static, str>`), so every newtype that carries the paired
593/// reverse `From<Self> for String` axis but not the paired
594/// [`Box<str>`] axis forces every [`Box<str>`]-typed call site through
595/// a `.to_string().into_boxed_str()` double-allocation detour that
596/// heap-allocates a fresh intermediary [`String`] between the wrapper
597/// and the [`Box<str>`] slot.
598///
599/// Opens the trait-idiomatic *owned-input, [`Box<str>`]*
600/// reverse-projection axis on the substrate's core String-wrapper
601/// newtype primitive [`CaixaVersion`], extending the reverse-projection
602/// matrix from the two axes already opened on this primitive (999a310
603/// on the [`String`] axis, 55532e5 on the [`Cow<'static, str>`] axis)
604/// onto the third. The fourth and final axis on the matrix
605/// ([`std::sync::Arc<str>`]) is closed by the sibling paired
606/// [`From<CaixaVersion> for std::sync::Arc<str>`] +
607/// [`From<&CaixaVersion> for std::sync::Arc<str>`] impls immediately below.
608///
609/// Pinned load-bearing by
610/// [`tests::caixa_version_from_into_owned_box_str_returns_wrapped_body`]
611/// (byte-parity pin against [`CaixaVersion::as_str`] on the same
612/// instance, plus a round-trip witness through the paired
613/// [`From<String> for CaixaVersion`] constructor closing the two-way
614/// `Self → Box<str> → Self` cycle by construction) and
615/// [`tests::caixa_version_from_into_owned_box_str_and_string_agree_on_every_shape`]
616/// (cross-axis partition pin against the paired owned-input
617/// [`From<CaixaVersion> for String`] and
618/// [`From<CaixaVersion> for Cow<'static, str>`] impls on the same
619/// instance, closing the "owned-input into [`String`] vs. owned-input
620/// into [`Cow<'static, str>`] vs. owned-input into [`Box<str>`]"
621/// three-corner bifurcation on the same wrapped body).
622impl From<CaixaVersion> for Box<str> {
623 fn from(v: CaixaVersion) -> Box<str> {
624 v.0.into_boxed_str()
625 }
626}
627
628/// Trait-idiomatic *borrowed-input, [`Box<str>`] output* reverse
629/// projection on the [`CaixaVersion`] newtype primitive — the
630/// borrowed-input companion to the paired owned-input
631/// [`From<CaixaVersion> for Box<str>`] impl immediately above. Routes
632/// byte-for-byte through the substrate-primitive
633/// [`CaixaVersion::as_str`] `pub const fn` accessor (via
634/// [`Box::<str>::from`]`(&str)`, which allocates a fit-to-length boxed
635/// slice from the borrowed `&str` in one heap allocation without an
636/// intermediary [`String`]) so every consumer that holds a borrowed
637/// [`&CaixaVersion`] and needs a [`Box<str>`] — a
638/// `[…].iter().map(Box::<str>::from).collect::<Vec<_>>()` per-instance
639/// materializer over `&[CaixaVersion]` (whose iterator yields
640/// `&CaixaVersion`, not `CaixaVersion`, so the paired owned-input
641/// [`From<CaixaVersion> for Box<str>`] axis alone forces every call
642/// site through an explicit `.clone()` / dereference restatement), a
643/// future `HashMap::<Box<str>, _>::from_iter` that keys off a
644/// borrowed-iteration axis, a future generic
645/// `<T: for<'a> Into<Box<str>>>`-bound emitter on a per-caixa
646/// diagnostic column that walks the `iter().map(Into::into)` shape
647/// verbatim — reaches the wrapped byte-string through this one dispatch
648/// on the substrate primitive.
649///
650/// Second corner on the `{Self, &Self} → Box<str>` reverse-projection
651/// family opened on the paired owned-input impl immediately above.
652/// Rust's `From` trait does not derive the `From<&Self>` sibling from
653/// a `From<Self>` impl (the blanket
654/// `impl<T, U> From<&T> for U where T: Clone, U: From<T>` does not
655/// exist in `core`), so every newtype that carries the owned-input
656/// reverse [`Box<str>`] axis but not the borrowed-input axis forces
657/// every borrowed call site through a `.clone()` /
658/// `<Box<str>>::from(v.clone())` detour whose type bounds have no
659/// compile-time link back to the newtype.
660///
661/// Pinned load-bearing by
662/// [`tests::caixa_version_from_borrowed_into_owned_box_str_routes_through_as_str_accessor`]
663/// (byte-parity pin against [`CaixaVersion::as_str`] via a borrowed
664/// input, plus a source-survival witness against silent move-out) and
665/// [`tests::caixa_version_from_owned_and_borrowed_into_box_str_agree_on_every_shape`]
666/// (cross-corner partition pin between owned-input move and
667/// borrowed-input clone on the same wrapped body through the
668/// [`Box<str>`] axis).
669impl From<&CaixaVersion> for Box<str> {
670 fn from(v: &CaixaVersion) -> Box<str> {
671 Box::<str>::from(v.as_str())
672 }
673}
674
675/// Trait-idiomatic *owned-input, [`std::sync::Arc<str>`] output* reverse
676/// projection on the [`CaixaVersion`] newtype primitive — the
677/// [`std::sync::Arc<str>`] companion to the paired owned-input
678/// [`From<CaixaVersion> for String`] (999a310),
679/// [`From<CaixaVersion> for std::borrow::Cow<'static, str>`] (55532e5),
680/// and [`From<CaixaVersion> for Box<str>`] (32d861a) impls on the same
681/// primitive. Routes through [`std::sync::Arc::<str>::from`]`(v.0)`,
682/// which allocates a fresh atomically-refcounted heap slab whose data
683/// slot byte-equals the wrapper's own [`String`] storage — the wrapped
684/// bytes move through by value into the `Arc<str>` layout in one heap
685/// allocation (the [`std::sync::Arc<str>`] layout carries a strong
686/// count + weak count header ahead of the byte slice, so a copy is
687/// required regardless of the input axis; no intermediary [`String`]
688/// or [`Box<str>`] is materialized on the owned-input path).
689///
690/// A future consumer that wants a [`std::sync::Arc<str>`]-typed handle
691/// on a [`CaixaVersion`] — a share-through-clone version body held
692/// across a per-caixa `caixa-operator` reconcile task where every
693/// spawn point wants a cheap `.clone()` on the version handle without
694/// each task re-allocating its own [`String`] copy (the
695/// [`std::sync::Arc::clone`] path bumps the atomic refcount in place
696/// and returns a pointer-width handle), a future
697/// `HashMap::<std::sync::Arc<str>, _>::from_iter` per-versao lookup
698/// where the map's key type is [`std::sync::Arc<str>`] so the same
699/// version-body pointer can key both the map and the payload without a
700/// second heap allocation, a future M4 admission-webhook decoder that
701/// materializes decoded version strings as [`std::sync::Arc<str>`]
702/// slices so downstream verdict-composer tasks running on separate
703/// worker threads can share the immutable body without a
704/// per-consumer [`String::clone`] — reaches the wrapped byte-string
705/// through this one dispatch, without the pre-lift
706/// `.to_string().into::<std::sync::Arc<str>>()` double-hop that would
707/// still allocate the same [`Arc<str>`] slab plus one intermediary
708/// [`String`] between the wrapper and the [`std::sync::Arc<str>`] slot.
709///
710/// Peer of the paired owned-input [`From<CaixaVersion> for String`]
711/// (999a310), [`From<CaixaVersion> for Cow<'static, str>`] (55532e5),
712/// and [`From<CaixaVersion> for Box<str>`] (32d861a) impls on the same
713/// primitive — all four route through `v.0` (the [`String`] axis
714/// returns the wrapped buffer verbatim; the [`Cow<'static, str>`] axis
715/// wraps it in [`Cow::Owned`]; the [`Box<str>`] axis shrinks it to a
716/// fit-to-length boxed slice; this axis copies the bytes into a fresh
717/// atomically-refcounted slab whose header carries the atomic strong +
718/// weak counters the [`std::sync::Arc<str>`] layout requires),
719/// preserving the substrate's single-dispatch reverse-projection
720/// discipline across the four axes. Rust's standard library does not
721/// derive `From<Self> for Arc<str>` from `From<Self> for String` (nor
722/// from `From<Self> for Box<str>` or `From<Self> for Cow<'static, str>`),
723/// so every newtype that carries the paired reverse `From<Self> for
724/// String` / `Box<str>` / `Cow<'static, str>` axes but not the paired
725/// [`std::sync::Arc<str>`] axis forces every
726/// [`std::sync::Arc<str>`]-typed call site through a
727/// `.to_string().into()` / `Arc::<str>::from(v.to_string())`
728/// double-allocation detour that heap-allocates a fresh intermediary
729/// [`String`] between the wrapper and the [`std::sync::Arc<str>`] slot.
730///
731/// Closes the trait-idiomatic *owned-input, [`std::sync::Arc<str>`]*
732/// reverse-projection axis on the substrate's core String-wrapper
733/// newtype primitive [`CaixaVersion`], completing the reverse-projection
734/// matrix on this primitive across the full `{String, Cow<'static, str>,
735/// Box<str>, Arc<str>}` roster — the fourth and final axis (999a310 on
736/// the [`String`] axis, 55532e5 on the [`Cow<'static, str>`] axis,
737/// 32d861a on the [`Box<str>`] axis, this axis on the
738/// [`std::sync::Arc<str>`] axis).
739///
740/// Pinned load-bearing by
741/// [`tests::caixa_version_from_into_owned_arc_str_returns_wrapped_body`]
742/// (byte-parity pin against [`CaixaVersion::as_str`] on the same
743/// instance, plus a round-trip witness through the paired
744/// [`From<String> for CaixaVersion`] constructor closing the two-way
745/// `Self → Arc<str> → Self` cycle by construction) and
746/// [`tests::caixa_version_from_into_owned_arc_str_and_string_agree_on_every_shape`]
747/// (cross-axis partition pin against the paired owned-input
748/// [`From<CaixaVersion> for String`], [`From<CaixaVersion> for Cow<'static, str>`],
749/// and [`From<CaixaVersion> for Box<str>`] impls on the same instance,
750/// closing the four-corner "owned-input into `String` vs. `Cow<'static, str>`
751/// vs. `Box<str>` vs. `Arc<str>`" partition on the same wrapped body).
752impl From<CaixaVersion> for std::sync::Arc<str> {
753 fn from(v: CaixaVersion) -> std::sync::Arc<str> {
754 std::sync::Arc::<str>::from(v.0)
755 }
756}
757
758/// Trait-idiomatic *borrowed-input, [`std::sync::Arc<str>`] output*
759/// reverse projection on the [`CaixaVersion`] newtype primitive — the
760/// borrowed-input companion to the paired owned-input
761/// [`From<CaixaVersion> for std::sync::Arc<str>`] impl immediately
762/// above. Routes byte-for-byte through the substrate-primitive
763/// [`CaixaVersion::as_str`] `pub const fn` accessor (via
764/// [`std::sync::Arc::<str>::from`]`(&str)`, which allocates a fresh
765/// atomically-refcounted heap slab from the borrowed `&str` in one
766/// heap allocation without an intermediary [`String`] or [`Box<str>`])
767/// so every consumer that holds a borrowed [`&CaixaVersion`] and needs
768/// a [`std::sync::Arc<str>`] — a
769/// `[…].iter().map(std::sync::Arc::<str>::from).collect::<Vec<_>>()`
770/// per-instance materializer over `&[CaixaVersion]` (whose iterator
771/// yields `&CaixaVersion`, not `CaixaVersion`, so the paired
772/// owned-input [`From<CaixaVersion> for std::sync::Arc<str>`] axis
773/// alone forces every call site through an explicit `.clone()` /
774/// dereference restatement), a future
775/// `HashMap::<std::sync::Arc<str>, _>::from_iter` that keys off a
776/// borrowed-iteration axis, a future generic
777/// `<T: for<'a> Into<std::sync::Arc<str>>>`-bound emitter on a
778/// per-caixa diagnostic column that walks the
779/// `iter().map(Into::into)` shape verbatim — reaches the wrapped
780/// byte-string through this one dispatch on the substrate primitive.
781///
782/// Second corner on the `{Self, &Self} → std::sync::Arc<str>`
783/// reverse-projection family opened on the paired owned-input impl
784/// immediately above. Rust's `From` trait does not derive the
785/// `From<&Self>` sibling from a `From<Self>` impl (the blanket
786/// `impl<T, U> From<&T> for U where T: Clone, U: From<T>` does not
787/// exist in `core`), so every newtype that carries the owned-input
788/// reverse [`std::sync::Arc<str>`] axis but not the borrowed-input
789/// axis forces every borrowed call site through a `.clone()` /
790/// `<std::sync::Arc<str>>::from(v.clone())` detour whose type bounds
791/// have no compile-time link back to the newtype.
792///
793/// Pinned load-bearing by
794/// [`tests::caixa_version_from_borrowed_into_owned_arc_str_routes_through_as_str_accessor`]
795/// (byte-parity pin against [`CaixaVersion::as_str`] via a borrowed
796/// input, plus a source-survival witness against silent move-out) and
797/// [`tests::caixa_version_from_owned_and_borrowed_into_arc_str_agree_on_every_shape`]
798/// (cross-corner partition pin between owned-input move and
799/// borrowed-input clone on the same wrapped body through the
800/// [`std::sync::Arc<str>`] axis).
801impl From<&CaixaVersion> for std::sync::Arc<str> {
802 fn from(v: &CaixaVersion) -> std::sync::Arc<str> {
803 std::sync::Arc::<str>::from(v.as_str())
804 }
805}
806
807/// Trait-idiomatic *owned-input, [`std::rc::Rc<str>`] output* reverse
808/// projection on the [`CaixaVersion`] newtype primitive — the owned-heap-
809/// string, single-threaded-reference-counted inverse of the pre-existing
810/// [`From<String> for CaixaVersion`] / [`From<&str> for CaixaVersion`]
811/// forward-projection pair on this primitive. Consumes the owned wrapper
812/// by value, moves the wrapped [`String`] into the [`std::rc::Rc<str>`]
813/// layout in one heap allocation (the [`std::rc::Rc<str>`] layout carries
814/// a strong count + weak count header ahead of the byte slice, so the copy
815/// is required regardless of the input axis; no intermediary [`String`] or
816/// [`Box<str>`] is materialized on the owned-input path) — the exact
817/// single-threaded mirror of the paired
818/// [`From<CaixaVersion> for std::sync::Arc<str>`] impl (3e67756) on the
819/// atomically-refcounted axis.
820///
821/// A future consumer that wants a [`std::rc::Rc<str>`]-typed handle on a
822/// [`CaixaVersion`] — a per-`feira` verb's single-threaded diagnostic
823/// composer that clones the version body across a chain of Nord-themed
824/// column emitters without paying either the [`String::clone`]
825/// full-allocation cost (every step re-allocates its own buffer) or the
826/// atomic-refcount overhead the paired [`std::sync::Arc<str>`] axis
827/// forces (the [`std::rc::Rc::clone`] path bumps a non-atomic refcount in
828/// place and returns a pointer-width handle, cheaper than the paired
829/// atomic increment on the sibling [`std::sync::Arc<str>`] axis by a
830/// measurable margin on hot single-threaded call sites), a future single-
831/// threaded `HashMap::<std::rc::Rc<str>, _>::from_iter` per-versao lookup
832/// where the map's key type is [`std::rc::Rc<str>`] so the same version-
833/// body pointer can key both the map and the payload without a second heap
834/// allocation, a future `feira lint` per-caixa diagnostic table whose
835/// per-column `Cell<std::rc::Rc<str>>` payload carries the version body
836/// across the row-composer + column-composer + wrapper phases through the
837/// pointer-width handle rather than a [`String`] per phase — reaches the
838/// wrapped byte-string through this one dispatch, without the pre-lift
839/// `.to_string().into::<std::rc::Rc<str>>()` double-hop that would still
840/// allocate the same [`Rc<str>`] slab plus one intermediary [`String`]
841/// between the wrapper and the [`std::rc::Rc<str>`] slot.
842///
843/// Peer of the paired owned-input [`From<CaixaVersion> for String`]
844/// (999a310), [`From<CaixaVersion> for Cow<'static, str>`] (55532e5),
845/// [`From<CaixaVersion> for Box<str>`] (32d861a), and
846/// [`From<CaixaVersion> for std::sync::Arc<str>`] (3e67756) impls on the
847/// same primitive — all five route through `v.0` (the [`String`] axis
848/// returns the wrapped buffer verbatim; the [`Cow<'static, str>`] axis
849/// wraps it in [`Cow::Owned`]; the [`Box<str>`] axis shrinks it to a
850/// fit-to-length boxed slice; the [`Arc<str>`] axis copies the bytes into
851/// a fresh atomically-refcounted slab; this axis copies the bytes into a
852/// fresh single-threaded-refcounted slab whose header carries the non-
853/// atomic strong + weak counters the [`std::rc::Rc<str>`] layout
854/// requires), preserving the substrate's single-dispatch reverse-
855/// projection discipline across the five axes. Rust's standard library
856/// does not derive `From<Self> for Rc<str>` from `From<Self> for Arc<str>`
857/// (the [`std::sync::Arc<str>`] and [`std::rc::Rc<str>`] layouts share the
858/// same on-disk shape but the trait tables are disjoint, and no blanket
859/// `impl<T> From<T> for Rc<str> where Arc<str>: From<T>` exists in
860/// `core`), so every newtype that carries the paired
861/// [`std::sync::Arc<str>`] axis but not the paired [`std::rc::Rc<str>`]
862/// axis forces every single-threaded [`std::rc::Rc<str>`]-typed call site
863/// through a `.to_string().into()` / `Rc::<str>::from(v.to_string())`
864/// double-allocation detour that heap-allocates a fresh intermediary
865/// [`String`] between the wrapper and the [`std::rc::Rc<str>`] slot.
866///
867/// Extends the trait-idiomatic *owned-input* reverse-projection matrix on
868/// the substrate's core String-wrapper newtype primitive [`CaixaVersion`]
869/// onto the single-threaded reference-counted axis — the fifth axis
870/// (999a310 on [`String`], 55532e5 on [`Cow<'static, str>`], 32d861a on
871/// [`Box<str>`], 3e67756 on [`std::sync::Arc<str>`], this axis on
872/// [`std::rc::Rc<str>`]).
873///
874/// Pinned load-bearing by
875/// [`tests::caixa_version_from_into_owned_rc_str_returns_wrapped_body`]
876/// (byte-parity pin against [`CaixaVersion::as_str`] on the same instance,
877/// plus a round-trip witness through the paired [`From<String> for
878/// CaixaVersion`] constructor closing the two-way `Self → Rc<str> → Self`
879/// cycle by construction) and
880/// [`tests::caixa_version_from_into_owned_rc_str_and_arc_str_agree_on_every_shape`]
881/// (cross-axis partition pin against the paired owned-input
882/// [`From<CaixaVersion> for String`],
883/// [`From<CaixaVersion> for Cow<'static, str>`],
884/// [`From<CaixaVersion> for Box<str>`], and
885/// [`From<CaixaVersion> for std::sync::Arc<str>`] impls on the same
886/// instance, closing the five-corner "owned-input into `String` vs.
887/// `Cow<'static, str>` vs. `Box<str>` vs. `Arc<str>` vs. `Rc<str>`"
888/// partition on the same wrapped body).
889impl From<CaixaVersion> for std::rc::Rc<str> {
890 fn from(v: CaixaVersion) -> std::rc::Rc<str> {
891 std::rc::Rc::<str>::from(v.0)
892 }
893}
894
895/// Trait-idiomatic *borrowed-input, [`std::rc::Rc<str>`] output* reverse
896/// projection on the [`CaixaVersion`] newtype primitive — the borrowed-
897/// input companion to the paired owned-input
898/// [`From<CaixaVersion> for std::rc::Rc<str>`] impl immediately above.
899/// Routes byte-for-byte through the substrate-primitive
900/// [`CaixaVersion::as_str`] `pub const fn` accessor (via
901/// [`std::rc::Rc::<str>::from`]`(&str)`, which allocates a fresh
902/// single-threaded-refcounted heap slab from the borrowed `&str` in one
903/// heap allocation without an intermediary [`String`] or [`Box<str>`]) so
904/// every consumer that holds a borrowed [`&CaixaVersion`] and needs a
905/// [`std::rc::Rc<str>`] — a
906/// `[…].iter().map(std::rc::Rc::<str>::from).collect::<Vec<_>>()`
907/// per-instance materializer over `&[CaixaVersion]` (whose iterator yields
908/// `&CaixaVersion`, not `CaixaVersion`, so the paired owned-input
909/// [`From<CaixaVersion> for std::rc::Rc<str>`] axis alone forces every
910/// call site through an explicit `.clone()` / dereference restatement), a
911/// future single-threaded `HashMap::<std::rc::Rc<str>, _>::from_iter` that
912/// keys off a borrowed-iteration axis, a future generic
913/// `<T: for<'a> Into<std::rc::Rc<str>>>`-bound emitter on a per-caixa
914/// diagnostic column that walks the `iter().map(Into::into)` shape
915/// verbatim — reaches the wrapped byte-string through this one dispatch on
916/// the substrate primitive.
917///
918/// Second corner on the `{Self, &Self} → std::rc::Rc<str>` reverse-
919/// projection family opened on the paired owned-input impl immediately
920/// above. Rust's `From` trait does not derive the `From<&Self>` sibling
921/// from a `From<Self>` impl (the blanket `impl<T, U> From<&T> for U where
922/// T: Clone, U: From<T>` does not exist in `core`), so every newtype that
923/// carries the owned-input reverse [`std::rc::Rc<str>`] axis but not the
924/// borrowed-input axis forces every borrowed call site through a
925/// `.clone()` / `<std::rc::Rc<str>>::from(v.clone())` detour whose type
926/// bounds have no compile-time link back to the newtype.
927///
928/// Pinned load-bearing by
929/// [`tests::caixa_version_from_borrowed_into_owned_rc_str_routes_through_as_str_accessor`]
930/// (byte-parity pin against [`CaixaVersion::as_str`] via a borrowed input,
931/// plus a source-survival witness against silent move-out) and
932/// [`tests::caixa_version_from_owned_and_borrowed_into_rc_str_agree_on_every_shape`]
933/// (cross-corner partition pin between owned-input move and borrowed-
934/// input clone on the same wrapped body through the [`std::rc::Rc<str>`]
935/// axis).
936impl From<&CaixaVersion> for std::rc::Rc<str> {
937 fn from(v: &CaixaVersion) -> std::rc::Rc<str> {
938 std::rc::Rc::<str>::from(v.as_str())
939 }
940}
941
942/// Trait-idiomatic *byte-view* borrow projection on the [`CaixaVersion`]
943/// newtype primitive — the byte-view mirror of the pre-existing sibling
944/// [`AsRef<str>`] str-view borrow projection on this same primitive.
945/// Routes byte-for-byte through the substrate-primitive
946/// [`CaixaVersion::as_str`] `pub const fn` accessor via [`str::as_bytes`]
947/// so every consumer that binds a [`CaixaVersion`] through the standard-
948/// library `impl AsRef<[u8]>` bound reaches the wrapped [`String`]'s
949/// byte-tail through one substrate-primitive dispatch rather than through
950/// the pre-lift open-coded `v.as_str().as_bytes()` /
951/// `<CaixaVersion as AsRef<str>>::as_ref(&v).as_bytes()` two-hop
952/// composition whose bounds carry no compile-time link back to the
953/// newtype's storage.
954///
955/// The primary compounding target is the [`crate`]-adjacent
956/// [`caixa-lacre`](../../caixa-lacre/) BLAKE3 content-address closure:
957/// [`blake3::hash`] and [`blake3::Hasher::update`] both bind their input
958/// through `impl AsRef<[u8]>`, so any future per-caixa content-address
959/// tag that folds a `:versao` byte-tail into the [`crate::Lacre`] closure
960/// (a hypothetical `hasher.update(caixa.versao());`-shape composition on
961/// the per-caixa BLAKE3 closure builder, a future per-`Membro :versao`
962/// requirement fold on the M3-mesh lacre snapshot the operator's
963/// admission cycle pins each Aplicacao's `:membros :versao` accept-set
964/// against, a future per-`ChildSpec :versao-requirement` fold on the
965/// M2-OTP-shape supervisor-tree lacre snapshot) reaches the substrate-
966/// primitive [`CaixaVersion::as_str`] accessor through this impl and no
967/// other. Peer consumer paths on the byte-view axis: any future
968/// [`std::io::Write::write_all`]-bound diagnostic sink (whose input binds
969/// through `impl AsRef<[u8]>`), any future byte-keyed
970/// [`std::collections::HashMap`] `<K: AsRef<[u8]>, V>` lookup whose entry-
971/// key trait bound rules out the sibling [`AsRef<str>`] str-view
972/// projection, and any future `ring::digest::Context::update` /
973/// `sha2::Sha256::update` / `blake3::Hasher::update` byte-input surface
974/// on any future per-`:versao` content-address digest.
975///
976/// Rust's standard library carries `impl AsRef<[u8]> for str` and
977/// `impl AsRef<[u8]> for String`, so the two-hop composition
978/// `v.as_str().as_bytes()` (equivalently
979/// `AsRef::<str>::as_ref(&v).as_bytes()`) is reachable through the pre-
980/// existing str-view axis alone. But that two-hop shape has no compile-
981/// time link back to the byte-projection axis, forces every downstream
982/// `<T: AsRef<[u8]>>`-bound consumer to open-code the two-hop composition
983/// at every call site rather than pass a [`CaixaVersion`] through the
984/// trait bound directly, and admits a silent split whenever a future call
985/// site takes a sibling reverse-projection axis (a `String::from(v)`
986/// unwrap, a `Box::<str>::from(&v)` fit-to-length boxed slice, a
987/// `Cow::<'static, str>::from(v)` owned-arm wrap) whose `.as_bytes()`
988/// byte-tail byte-equals `as_str`'s by construction but carries no
989/// compile-time byte-view surface. The lifted single-hop impl closes the
990/// byte-view axis so every future `<T: AsRef<[u8]>>`-bound consumer
991/// reaches the substrate primitive through one trait dispatch, and any
992/// future rebrand of the wrapped storage (a hypothetical widening to a
993/// typed [`semver::Version`] slot once eager parse-on-construct
994/// discipline lands) migrates the byte-view surface in lockstep with the
995/// paired [`AsRef<str>`] / [`fmt::Display`] / [`std::borrow::Borrow<str>`]
996/// projections at the shared [`CaixaVersion::as_str`] accessor.
997///
998/// Rust-side newtype convention pairs [`AsRef<str>`] and [`AsRef<[u8]>`]
999/// on the same primitive (the standard library's own [`String`] carries
1000/// both — `impl AsRef<str> for String` + `impl AsRef<[u8]> for String` —
1001/// on the same borrow-projection axis), so a newtype that carries one but
1002/// not the other splits off the convention that lets every
1003/// [`String`]-shaped consumer swap the newtype in without re-shaping its
1004/// bounds. This impl closes that split on [`CaixaVersion`], mirroring the
1005/// paired [`AsRef<[u8]>`] byte-view axis every closed-set fieldless typed
1006/// enum peer on the substrate already carries
1007/// ([`crate::CaixaKind`] at kind.rs:1791, [`crate::CaixaDialeto`] at
1008/// dialeto.rs:1885, [`crate::dep::DepList`] at dep.rs:4616,
1009/// [`crate::supervisor::RestartStrategy`] at supervisor.rs:1518,
1010/// [`crate::supervisor::RestartPolicy`] at supervisor.rs:3385,
1011/// [`crate::aplicacao::WitShape`] at aplicacao.rs:1955,
1012/// [`crate::aplicacao::RateLimitUnit`] at aplicacao.rs:8900,
1013/// [`crate::aplicacao::PlacementStrategy`] at aplicacao.rs:12231), now
1014/// extended onto the substrate's core String-wrapper newtype primitive.
1015/// The str-view axes stay reachable for the borrowed `&str` and
1016/// formatter-output paths, this impl closes the byte-view axis at the
1017/// same shared substrate-primitive accessor.
1018///
1019/// Pinned load-bearing by
1020/// [`tests::caixa_version_as_ref_bytes_routes_through_as_str_accessor`]
1021/// (byte-parity pin against [`CaixaVersion::as_str`] `.as_bytes()`, plus
1022/// cross-axis witness against the paired [`AsRef<str>`] and
1023/// [`fmt::Display`] axes' `.as_bytes()` byte-tails, plus a
1024/// `<T: AsRef<[u8]>>`-bound-consumer witness that a generic byte-input
1025/// function accepts a [`CaixaVersion`] directly through the trait bound
1026/// and reaches the wrapped body without the caller open-coding the
1027/// two-hop projection). Any future silent detour that routes the byte-
1028/// view impl off the substrate-primitive [`CaixaVersion::as_str`]
1029/// accessor (a swap onto `self.0.as_bytes()` re-inlining that bypasses
1030/// the shared `pub const fn` dispatch, a stray normalization step that
1031/// would drop whitespace or canonicalize a prerelease tag ahead of the
1032/// byte-view emit, a swap onto a hypothetical future [`semver::Version`]
1033/// re-serialization that would strip the raw at-rest storage discipline
1034/// [`CaixaVersion`] carries by construction) trips at caixa-core test
1035/// time under `assert_eq!` rather than at a downstream `impl AsRef<[u8]>`-
1036/// bound consumer's silent split.
1037impl AsRef<[u8]> for CaixaVersion {
1038 fn as_ref(&self) -> &[u8] {
1039 self.as_str().as_bytes()
1040 }
1041}
1042
1043/// Trait-idiomatic *owned-input, owned-[`Vec<u8>`] output* byte-owned
1044/// forward projection on the [`CaixaVersion`] newtype primitive — the
1045/// byte-mirror of the pre-existing owned-input [`From<CaixaVersion> for
1046/// String`] str-owned forward-projection axis and the owned-heap peer of
1047/// the borrow-projection [`AsRef<[u8]>`] byte-view axis (the prior lift on
1048/// this same primitive) that only surfaces a `&[u8]` view without an
1049/// owned-heap byte-tail.
1050///
1051/// Routes the wrapped [`String`] storage through
1052/// [`String::into_bytes`] verbatim ([`Self::0`], a move of the pre-existing
1053/// heap allocation reused byte-for-byte as the [`Vec<u8>`] backing buffer —
1054/// no re-copy of the per-instance version body's bytes, no allocating
1055/// detour through `.as_str().as_bytes().to_vec()`), so every consumer
1056/// that binds a [`CaixaVersion`] through the standard-library `.into()` /
1057/// [`From<Self> for Vec<u8>`] (equivalently [`Into<Vec<u8>>`]) axis
1058/// reaches the wrapped byte-string through one substrate-primitive
1059/// dispatch on the exact same heap allocation the manifest-parse forward
1060/// [`From<String> for CaixaVersion`] constructor accepted.
1061///
1062/// A future consumer that wants an owned [`Vec<u8>`] byte-tail on a
1063/// [`CaixaVersion`] — a future
1064/// [`std::io::Write::write_all`]-shape per-caixa `:versao` audit-log
1065/// byte-sink whose input parameter is an owned [`Vec<u8>`] payload, a
1066/// future `bytes::Bytes::from(Vec::<u8>::from(v))` composer folding the
1067/// canonical `SemVer` wire form into a [`bytes::Bytes`] framing surface,
1068/// a future `hasher.update(&Vec::<u8>::from(v))`-shape BLAKE3 content-
1069/// address closure that needs the owned byte-tail buffered before folding
1070/// into the per-caixa [`crate::Lacre`] closure body, a future per-caixa
1071/// protobuf/CBOR/msgpack payload composer whose framer takes an owned
1072/// [`Vec<u8>`] rather than a borrowed byte-slice, a future M4 admission-
1073/// webhook rejection body composer that emits the offending
1074/// [`CaixaVersion`] as a raw byte-tail through an
1075/// [`std::io::Write`]-shape sink — reaches the substrate primitive
1076/// through one trait dispatch, avoiding the pre-lift open-coded
1077/// `v.as_str().as_bytes().to_vec()` two-hop composition (a fresh heap
1078/// allocation copied byte-by-byte off the wrapper's own storage) or the
1079/// `String::from(v).into_bytes()` two-hop reverse-then-move shape whose
1080/// intermediate `String` step carries no compile-time link back to the
1081/// byte-view axis.
1082///
1083/// Peer of the pre-existing byte-view [`AsRef<[u8]>`] impl on the same
1084/// primitive — both project the wrapped [`String`] onto its byte-tail,
1085/// but the [`AsRef<[u8]>`] axis surfaces a borrowed `&[u8]` view for
1086/// consumers that never take ownership while this impl surfaces an owned
1087/// [`Vec<u8>`] for consumers whose framing / sink / hasher / channel
1088/// surfaces demand a heap-owned buffer. Rust's standard library
1089/// deliberately splits the two axes on the two bounds they carry
1090/// (`impl AsRef<[u8]> for String` for the borrowed-view surface,
1091/// `impl From<String> for Vec<u8>` via [`String::into_bytes`] for the
1092/// owned-heap surface), so a newtype that carries one but not the other
1093/// splits off the convention that lets every [`String`]-shaped consumer
1094/// swap the newtype in without re-shaping its bounds.
1095///
1096/// Opens the trait-idiomatic *owned-input, [`Vec<u8>`]* byte-owned
1097/// forward-projection axis on the substrate's core String-wrapper newtype
1098/// primitive [`CaixaVersion`], mirroring the paired
1099/// `From<{Self, &Self}> for Vec<u8>` axis every sibling closed-set
1100/// fieldless typed enum peer on the substrate already carries
1101/// ([`crate::CaixaKind`], [`crate::CaixaDialeto`], [`crate::dep::DepList`],
1102/// [`crate::supervisor::RestartStrategy`],
1103/// [`crate::supervisor::RestartPolicy`], [`crate::aplicacao::WitShape`],
1104/// [`crate::aplicacao::RateLimitUnit`],
1105/// [`crate::aplicacao::PlacementStrategy`], and the compound sibling
1106/// [`crate::aplicacao::RateLimit`] at aplicacao.rs:6743 which routes
1107/// through its paired [`fmt::Display`] via `.to_string().into_bytes()`),
1108/// now extended onto the substrate's core String-wrapper newtype
1109/// primitive.
1110///
1111/// Pinned load-bearing by
1112/// [`tests::caixa_version_from_into_owned_vec_bytes_returns_wrapped_body`]
1113/// (byte-parity pin against [`CaixaVersion::as_str`] `.as_bytes()` on the
1114/// same instance, plus a round-trip witness through the paired
1115/// [`From<String> for CaixaVersion`] constructor after re-materializing
1116/// the [`Vec<u8>`] through [`String::from_utf8`]) and
1117/// [`tests::caixa_version_from_owned_and_borrowed_into_vec_bytes_agree_on_every_shape`]
1118/// (cross-axis partition pin against the paired borrowed-input impl and
1119/// against the pre-existing byte-view [`AsRef<[u8]>`] axis on the same
1120/// instance, closing the "owned-input move vs. borrowed-input clone" and
1121/// "owned-heap vs. borrowed-view" bifurcations on the same wrapped body).
1122impl From<CaixaVersion> for Vec<u8> {
1123 fn from(v: CaixaVersion) -> Vec<u8> {
1124 v.0.into_bytes()
1125 }
1126}
1127
1128/// Trait-idiomatic *borrowed-input, owned-[`Vec<u8>`] output* byte-owned
1129/// forward projection on the [`CaixaVersion`] newtype primitive — the
1130/// borrowed-input companion to the paired owned-input
1131/// [`From<CaixaVersion> for Vec<u8>`] impl immediately above. Routes
1132/// byte-for-byte through the substrate-primitive
1133/// [`CaixaVersion::as_str`] `pub const fn` accessor (via
1134/// [`str::as_bytes`] + [`slice::to_vec`]) so every consumer that holds a
1135/// borrowed [`&CaixaVersion`] and needs an owned [`Vec<u8>`] — a
1136/// `[…].iter().map(Vec::<u8>::from).collect::<Vec<_>>()` per-instance
1137/// materializer over `&[CaixaVersion]` (whose iterator yields
1138/// `&CaixaVersion`, not `CaixaVersion`, so the owned-input
1139/// [`From<CaixaVersion> for Vec<u8>`] axis alone forces every call site
1140/// through an explicit `.clone()` restatement whose intermediate
1141/// [`CaixaVersion`] allocation is discarded on the very next call), a
1142/// future admission-webhook diagnostic body composer that walks a
1143/// `&Vec<CaixaVersion>` overlay through an [`Into<Vec<u8>>`]-bound per-
1144/// arm byte-writer to surface each offending `:versao` wire form, a
1145/// future per-`Membro :versao`-shape audit-log byte-writer that folds
1146/// each Aplicacao's member-versao byte-tail into an owned [`Vec<u8>`]
1147/// sink without moving out of the borrowed [`AplicacaoSpec::membros`]
1148/// slice — reaches the wrapped byte-string through this one dispatch on
1149/// the substrate primitive.
1150///
1151/// Second corner on the `{Self, &Self} → Vec<u8>` byte-owned forward-
1152/// projection family opened on the paired owned-input
1153/// [`From<CaixaVersion> for Vec<u8>`] impl immediately above. Rust's
1154/// `From` trait does not derive the `From<&Self>` sibling from a
1155/// `From<Self>` impl (the blanket
1156/// `impl<T, U> From<&T> for U where T: Clone, U: From<T>` does not exist
1157/// in `core`), so every newtype that carries the owned-input byte-owned
1158/// forward axis but not the borrowed-input axis forces every borrowed
1159/// call site through a `.clone()` / `<Vec<u8>>::from(v.clone())` detour
1160/// whose type bounds have no compile-time link back to the newtype.
1161///
1162/// Pinned load-bearing by
1163/// [`tests::caixa_version_from_borrowed_into_owned_vec_bytes_routes_through_as_str_accessor`]
1164/// (byte-parity pin against [`CaixaVersion::as_str`] `.as_bytes()` via a
1165/// borrowed input, plus a source-survival witness against silent move-
1166/// out) and
1167/// [`tests::caixa_version_from_owned_and_borrowed_into_vec_bytes_agree_on_every_shape`]
1168/// (cross-corner partition pin between owned-input move and borrowed-
1169/// input clone on the same wrapped body through the [`Vec<u8>`] axis).
1170impl From<&CaixaVersion> for Vec<u8> {
1171 fn from(v: &CaixaVersion) -> Vec<u8> {
1172 v.as_str().as_bytes().to_vec()
1173 }
1174}
1175
1176/// Trait-idiomatic *owned-input, [`std::borrow::Cow<'static, [u8]>`]
1177/// output* byte-owned reverse projection on the [`CaixaVersion`] newtype
1178/// primitive — the [`Cow<'static, [u8]>`] companion to the paired owned-
1179/// input [`From<CaixaVersion> for Vec<u8>`] impl (98d38ed) on the same
1180/// primitive, mirroring the sibling str-family [`From<CaixaVersion> for
1181/// std::borrow::Cow<'static, str>`] axis (55532e5) onto the byte-family
1182/// side of the reverse-projection matrix. Routes through
1183/// [`std::borrow::Cow::Owned`]`(v.0.into_bytes())`, moving the wrapper's
1184/// own heap allocation through [`String::into_bytes`] verbatim — no
1185/// re-copy of the per-instance version body's bytes on the owned-input
1186/// path, no allocating detour through [`CaixaVersion::as_str`] +
1187/// [`slice::to_vec`], no mis-routing onto [`Cow::Borrowed`] on a
1188/// runtime byte-string that cannot promise the `&'static [u8]` lifetime
1189/// the borrowed arm requires.
1190///
1191/// A future consumer that wants a [`Cow<'static, [u8]>`]-typed handle
1192/// on a [`CaixaVersion`] — a
1193/// `tracing::field::Value::Bytes(caixa.versao.into())`-shape structured-
1194/// log key on a future per-caixa `caixa-operator` reconciliation counter
1195/// (whose byte-tail emit surface types byte-keys as
1196/// [`Cow<'static, [u8]>`] so static compile-time literals and dynamic
1197/// version bodies share the same key-slot without an unconditional heap
1198/// allocation on the literal path), a future
1199/// `HashMap::<Cow<'static, [u8]>, _>::from_iter([(versao.into(), _)])`
1200/// per-versao lookup where the map's key type is [`Cow<'static, [u8]>`]
1201/// rather than owned [`Vec<u8>`] so literal-lifetime byte-keys can share
1202/// the same map without wrapping in an extra [`Vec<u8>`] allocation, a
1203/// future M4 admission-webhook rejection body whose per-arm error-frame
1204/// composer accepts a [`Cow<'static, [u8]>`] intermediate for the same
1205/// reason — reaches the wrapped byte-string through this one dispatch,
1206/// without the pre-lift `Vec::<u8>::from(v).into()` /
1207/// `Cow::Owned(Vec::from(v))` double-hop that would still allocate the
1208/// same [`Cow::Owned`] arm through the sibling byte-owned axis.
1209///
1210/// Deliberately returns [`std::borrow::Cow::Owned`] rather than
1211/// [`std::borrow::Cow::Borrowed`] — the substrate-primitive
1212/// [`CaixaVersion::as_str`] accessor's `.as_bytes()` return does not
1213/// carry the `&'static [u8]` lifetime by construction (the wrapped
1214/// [`String`] storage is a runtime heap allocation, not a compile-time
1215/// literal), so the [`Cow<'static, [u8]>`] output shape rules out the
1216/// borrowed arm and the owned arm is the type-correct projection
1217/// (mirroring the paired sibling [`From<CaixaVersion> for
1218/// std::borrow::Cow<'static, str>`] axis's own [`Cow::Owned`] discipline
1219/// at 55532e5). Peer of the paired owned-input
1220/// [`From<CaixaVersion> for Vec<u8>`] impl (98d38ed) on the same
1221/// primitive — both route through the wrapper's own heap allocation via
1222/// a move on `v.0.into_bytes()`, preserving the zero-copy discipline the
1223/// substrate opens on its String-wrapper newtype primitive across the
1224/// byte-family reverse-projection matrix.
1225///
1226/// Extends the trait-idiomatic *owned-input* byte-family reverse-
1227/// projection matrix on the substrate's core String-wrapper newtype
1228/// primitive [`CaixaVersion`] onto the [`Cow<'static, [u8]>`] axis —
1229/// the second corner (98d38ed on [`Vec<u8>`], this axis on
1230/// [`Cow<'static, [u8]>`]) on the byte-family side, mirroring the
1231/// paired str-family axis at 55532e5 on [`Cow<'static, str>`]. Rust's
1232/// standard library does not derive `From<Self> for Cow<'static, [u8]>`
1233/// from `From<Self> for Vec<u8>` (nor from `From<Self> for Cow<'static,
1234/// str>`), so every newtype that carries a byte-owned [`Vec<u8>`]
1235/// reverse axis but not the paired [`Cow<'static, [u8]>`] axis forces
1236/// every [`Cow<'static, [u8]>`]-typed call site through a
1237/// `Vec::<u8>::from(v).into()` intermediary allocation whose bounds
1238/// carry no compile-time link back to the newtype's storage.
1239///
1240/// Pinned load-bearing by
1241/// [`tests::caixa_version_from_into_owned_cow_bytes_returns_owned_wrapped_body`]
1242/// (byte-parity + [`Cow::Owned`]-arm pin against
1243/// [`CaixaVersion::as_str`] `.as_bytes()` on the same instance, plus a
1244/// round-trip witness through the paired [`From<String> for
1245/// CaixaVersion`] constructor after re-materializing the byte-tail
1246/// through [`String::from_utf8`]) and
1247/// [`tests::caixa_version_from_into_owned_cow_bytes_and_vec_bytes_agree_on_every_shape`]
1248/// (cross-axis partition pin against the paired owned-input
1249/// [`From<CaixaVersion> for Vec<u8>`] and pre-existing byte-view
1250/// [`AsRef<[u8]>`] impls on the same instance, closing the "owned-input
1251/// into [`Vec<u8>`] vs. owned-input into [`Cow<'static, [u8]>`]"
1252/// bifurcation on the same wrapped body).
1253impl From<CaixaVersion> for std::borrow::Cow<'static, [u8]> {
1254 fn from(v: CaixaVersion) -> std::borrow::Cow<'static, [u8]> {
1255 std::borrow::Cow::Owned(v.0.into_bytes())
1256 }
1257}
1258
1259/// Trait-idiomatic *borrowed-input, [`std::borrow::Cow<'static, [u8]>`]
1260/// output* byte-owned reverse projection on the [`CaixaVersion`] newtype
1261/// primitive — the borrowed-input companion to the paired owned-input
1262/// [`From<CaixaVersion> for std::borrow::Cow<'static, [u8]>`] impl
1263/// immediately above. Routes byte-for-byte through the substrate-
1264/// primitive [`CaixaVersion::as_str`] `pub const fn` accessor (via
1265/// [`str::as_bytes`] + [`slice::to_vec`] wrapped in
1266/// [`std::borrow::Cow::Owned`]) so every consumer that holds a borrowed
1267/// [`&CaixaVersion`] and needs a [`Cow<'static, [u8]>`] — a
1268/// `[…].iter().map(Cow::<'static, [u8]>::from).collect::<Vec<_>>()`
1269/// per-instance materializer over `&[CaixaVersion]` (whose iterator
1270/// yields `&CaixaVersion`, not `CaixaVersion`, so the paired owned-input
1271/// [`From<CaixaVersion> for Cow<'static, [u8]>`] axis alone forces every
1272/// call site through an explicit `.clone()` / dereference restatement),
1273/// a future `HashMap::<Cow<'static, [u8]>, _>::from_iter` that keys off
1274/// a borrowed-iteration axis where cloning the wrapper would allocate
1275/// one [`String`] beyond the eventual [`Cow::Owned`] arm's own, a future
1276/// generic `<T: for<'a> Into<Cow<'static, [u8]>>>`-bound byte-writer on
1277/// a per-caixa diagnostic column that walks the
1278/// `iter().map(Into::into)` shape verbatim — reaches the wrapped
1279/// byte-string through this one dispatch on the substrate primitive.
1280///
1281/// Deliberately returns [`std::borrow::Cow::Owned`] rather than
1282/// [`std::borrow::Cow::Borrowed`] — the substrate-primitive
1283/// [`CaixaVersion::as_str`] accessor's `.as_bytes()` return does not
1284/// carry the `&'static [u8]` lifetime by construction, so the
1285/// [`Cow<'static, [u8]>`] output shape rules out the borrowed arm and
1286/// the owned arm is the type-correct projection (mirroring the paired
1287/// owned-input impl's own [`Cow::Owned`] discipline). Second corner on
1288/// the `{Self, &Self} → Cow<'static, [u8]>` byte-owned reverse-
1289/// projection family opened on the paired owned-input impl immediately
1290/// above. Rust's `From` trait does not derive the `From<&Self>` sibling
1291/// from a `From<Self>` impl (the blanket
1292/// `impl<T, U> From<&T> for U where T: Clone, U: From<T>` does not exist
1293/// in `core`), so every newtype that carries the owned-input byte-owned
1294/// reverse [`Cow<'static, [u8]>`] axis but not the borrowed-input axis
1295/// forces every borrowed call site through a `.clone()` /
1296/// `<Cow<'static, [u8]>>::from(v.clone())` detour whose type bounds
1297/// have no compile-time link back to the newtype.
1298///
1299/// Pinned load-bearing by
1300/// [`tests::caixa_version_from_borrowed_into_owned_cow_bytes_routes_through_as_str_accessor`]
1301/// (byte-parity + [`Cow::Owned`]-arm pin against
1302/// [`CaixaVersion::as_str`] `.as_bytes()` via a borrowed input, plus a
1303/// source-survival witness against silent move-out) and
1304/// [`tests::caixa_version_from_owned_and_borrowed_into_cow_bytes_agree_on_every_shape`]
1305/// (cross-corner partition pin between owned-input move and borrowed-
1306/// input clone on the same wrapped body through the [`Cow<'static,
1307/// [u8]>`] axis).
1308impl From<&CaixaVersion> for std::borrow::Cow<'static, [u8]> {
1309 fn from(v: &CaixaVersion) -> std::borrow::Cow<'static, [u8]> {
1310 std::borrow::Cow::Owned(v.as_str().as_bytes().to_vec())
1311 }
1312}
1313
1314/// Canonical Zig-style git-tag prefix every `feira publish` run writes
1315/// and every downstream consumer of a published caixa reads. A caixa
1316/// published at `:versao "0.1.0"` lands as a git tag `v0.1.0` on the
1317/// source repo's `origin` remote — the [`crate::CaixaVersion`] value
1318/// gates the version body, this constant gates the prefix the body
1319/// composes under.
1320///
1321/// Two production-code consumers carry this prefix on the same git
1322/// remote axis:
1323///
1324/// 1. [`caixa-feira`]'s `feira publish` verb (caixa-feira/src/cmd/publish.rs)
1325/// — the writer. Its `--prefix` clap flag defaults to this string
1326/// and the verb computes the tag as `format!("{prefix}{versao}")`
1327/// before `git tag -a <tag>` + `git push origin <tag>`.
1328/// 2. [`caixa-flux`]'s [`caixa-flux::cluster_bundle`] renderer
1329/// (caixa-flux/src/lib.rs) — the reader. Its
1330/// `ClusterBundleOpts::for_caixa` constructor defaults
1331/// `git_ref: GitRefSpec::Tag(...)` to `<prefix><versao>` so the
1332/// rendered `gitrepository.yaml` carries `ref: { tag: v<versao> }`
1333/// pointing `FluxCD`'s `GitRepository` reconciler at the exact tag
1334/// the publisher just wrote.
1335///
1336/// Until this lift landed both consumers carried the bare `"v"` byte
1337/// inline — `caixa-feira/src/cmd/publish.rs:22`'s clap
1338/// `default_value = "v"` and `caixa-flux/src/lib.rs:335`'s
1339/// `format!("v{}", caixa.versao)` literal. A future Zig-style-tag
1340/// convention rebrand (the substrate moving to plain `<versao>` tags
1341/// once the GitHub releases UI normalizes around the bare form, to
1342/// `release/<versao>` once a sibling forge convention adopts the
1343/// `<type>/<value>` slash-namespaced shape, or to a per-edition
1344/// override the operator pins through a future `:placement
1345/// :tag-prefix` slot) without a coordinated edit on both sides would
1346/// silently emit a `feira publish`-side tag at one shape (e.g.
1347/// `release/0.1.0`) and a `cluster_bundle`-side `ref: { tag: v0.1.0 }`
1348/// pointing at the prior shape — Flux's `GitRepository` reconciler
1349/// would loop forever looking for an upstream `v0.1.0` ref the publish
1350/// remote no longer carries, the dependent `HelmRelease`'s `chart:
1351/// sourceRef` would never resolve, every per-Servico apply would
1352/// silently come up with the prior reconciled state, and the failure
1353/// would surface at `kubectl describe gitrepository` time (the
1354/// `Status: Stalled` / `Reason: Failed` arm) far from the rebrand
1355/// commit's source.
1356///
1357/// Lifting the literal to one `&'static str` constant closes the drift
1358/// footgun structurally — both consumers read from the same memory,
1359/// so any future rebrand reaches both sites by construction and a CI
1360/// build that re-introduces a sibling inline `"v"` literal trips the
1361/// peer pinning tests
1362/// ([`caixa-feira`]'s `publish_prefix_default_pins_lifted_caixa_core_constant`,
1363/// [`caixa-flux`]'s `cluster_bundle_default_git_tag_uses_lifted_caixa_core_prefix`)
1364/// at the build-time fail-before-deploy posture every prior
1365/// load-bearing-string lift on this surface
1366/// ([`crate::DEFAULT_NAMESPACE`] a085b26,
1367/// [`crate::DEFAULT_LIBRARY_NAME`] 41438dc,
1368/// [`crate::DEFAULT_SERVICO_PORT`] 1e22add) establishes.
1369///
1370/// Authoring-side `:versao` gates already refuse the `"v"`-prefixed
1371/// publish tag shape leaking back into a version body — every typed
1372/// `:versao` surface (top-level `:versao`, `:upgrade-from :from`,
1373/// `:deps :versao`, `:deps-dev :versao`, `:membros :versao`,
1374/// `:children :versao`) routes through `semver::Version::parse` /
1375/// [`parse_requirement`], both of which reject the `v`-prefix as
1376/// invalid `SemVer`. The split — bare `SemVer` at the `:versao` slot,
1377/// `v<versao>` at the published git-tag axis — is the convention this
1378/// constant pins.
1379pub const DEFAULT_PUBLISH_TAG_PREFIX: &str = "v";
1380
1381/// Canonical git remote name every `feira` writer-side verb pushes to —
1382/// the destination handle the operator-out-of-the-loop publish + deploy
1383/// chain (`feira publish`, `feira deploy --apply`, `feira app deploy
1384/// --apply`) names when it invokes `git push <remote> <ref>` against
1385/// the local clone of the source / k8s GitOps repo.
1386///
1387/// Three production-code consumers carry this remote name on the same
1388/// `git push` axis:
1389///
1390/// 1. [`caixa-feira`]'s `feira publish` verb (caixa-feira/src/cmd/publish.rs)
1391/// — the writer-side publish path. Its `--remote` clap flag defaults
1392/// to this string and the verb runs `git push <remote> <tag>` to push
1393/// the freshly written `v<versao>` tag upstream.
1394/// 2. [`caixa-feira`]'s `feira deploy --apply` verb
1395/// (caixa-feira/src/cmd/deploy.rs) — the writer-side Servico cluster-
1396/// deploy path. Its `push_origin` helper runs `git push origin HEAD`
1397/// against the k8s GitOps repo's working tree after upserting the
1398/// Servico's entry into the cluster's lareira-fleet-programs
1399/// HelmRelease values.
1400/// 3. [`caixa-feira`]'s `feira app deploy --apply` verb
1401/// (caixa-feira/src/cmd/app.rs) — the writer-side Aplicacao
1402/// cluster-deploy path. Its `push_origin` helper runs the same
1403/// `git push origin HEAD` against the k8s GitOps repo after writing
1404/// the rendered multi-doc YAML (programs.yaml entries + Cilium
1405/// NetworkPolicies + Gateway/HTTPRoute) to the cluster's tree.
1406///
1407/// Until this lift landed all three consumers carried the bare
1408/// `"origin"` byte inline — `publish.rs`'s clap `default_value = "origin"`,
1409/// `deploy.rs`'s `git(repo, ["push", "origin", "HEAD"])`, and
1410/// `app.rs`'s `git(repo, ["push", "origin", "HEAD"])`. A future
1411/// remote-naming-convention rebrand on any one side (the substrate
1412/// moving to `upstream` for forge-mirror clusters, to a per-tenant
1413/// remote naming convention once the operator-flux pipeline grows the
1414/// `:placement :remote` slot, or to the canonical multi-remote
1415/// `release` + `mirror` split every Erlang/OTP `release_handler` /
1416/// `relup` shop converges on once their git surface grows past one
1417/// upstream) without a coordinated edit on the other two would have
1418/// silently emitted a `git push` against a remote that doesn't exist
1419/// on the operator's clone (`fatal: '<remote>' does not appear to be
1420/// a git repository`) on one writer verb while the other two still
1421/// pushed to the old remote — operator-observed symptom: the publish
1422/// landed but the deploy didn't, or vice-versa, with the failure
1423/// surfacing as a partial-state rollout far from the rebrand commit's
1424/// source.
1425///
1426/// Lifting the literal to one `&'static str` constant closes the drift
1427/// footgun structurally — all three consumers read from the same
1428/// memory, so any future remote-naming rebrand reaches every writer
1429/// verb by construction and a CI build that re-introduces a sibling
1430/// inline `"origin"` literal trips the peer pinning tests
1431/// ([`caixa-feira`]'s `publish_remote_default_pins_lifted_caixa_core_constant`
1432/// on the clap-default axis, the sibling structural pins on the two
1433/// `push_origin` helpers) at the build-time fail-before-deploy
1434/// posture every prior load-bearing-string lift on this surface
1435/// ([`crate::DEFAULT_NAMESPACE`] a085b26, [`crate::DEFAULT_LIBRARY_NAME`]
1436/// 41438dc, [`crate::DEFAULT_SERVICO_PORT`] 1e22add,
1437/// [`crate::DEFAULT_PUBLISH_TAG_PREFIX`] 0a6a602,
1438/// [`crate::DEFAULT_FLUX_SYSTEM_NAMESPACE`] 7197d38) establishes.
1439///
1440/// Pairs with [`DEFAULT_PUBLISH_TAG_PREFIX`] on the same git remote
1441/// axis — `feira publish` runs `git push <DEFAULT_GIT_REMOTE>
1442/// <DEFAULT_PUBLISH_TAG_PREFIX><versao>` to push the typed `:versao`
1443/// body composed under the canonical prefix to the canonical remote.
1444/// Both halves of the publish-side convention now live in one place.
1445pub const DEFAULT_GIT_REMOTE: &str = "origin";
1446
1447/// Canonical GitHub org name the pleme-io substrate defaults every un-
1448/// pinned caixa's source repo to — the org handle the two substrate-side
1449/// "no `:repositorio` / no `:fonte` declared, fall back to the canonical
1450/// org" paths compose their `github:<org>/<nome>` shorthand + full
1451/// `https://github.com/<org>/<nome>` URL under.
1452///
1453/// Two production-code consumers carry this org name on the same
1454/// canonical-substrate-default-git-org axis:
1455///
1456/// 1. [`caixa-feira`]'s `feira lock` verb's `resolve_stub` (caixa-feira/src/cmd/lock.rs)
1457/// — the resolver-side default. When a declared dep has no
1458/// `:fonte` block the stub resolver composes
1459/// `caixa_core::DepSource::default_github(<org>, &dep.nome)` to fill
1460/// the shorthand `github:<org>/<nome>` fallback the phase 1.B
1461/// `feira resolve` walker will resolve against upstream.
1462/// 2. [`caixa-flux`]'s [`caixa-flux::cluster_bundle`] renderer
1463/// (caixa-flux/src/lib.rs) — the renderer-side default. Its
1464/// `ClusterBundleOpts::for_caixa` constructor defaults
1465/// `git_url` to `format!("https://github.com/{org}/{}", caixa.nome)`
1466/// when the caixa carries no `:repositorio`, so the rendered
1467/// `gitrepository.yaml` points `FluxCD`'s `GitRepository`
1468/// reconciler at the substrate's canonical git host for un-pinned
1469/// caixas.
1470///
1471/// Until this lift landed both consumers carried the bare `"pleme-io"`
1472/// byte inline — `caixa-feira/src/cmd/lock.rs:61`'s
1473/// `default_github("pleme-io", …)` call and `caixa-flux/src/lib.rs`'s
1474/// `format!("https://github.com/pleme-io/{}", …)` literal. A future
1475/// substrate-side git-org migration (the pleme-io org renaming to a
1476/// short form, forking to a per-tenant `<org>-<tenant>` shape once the
1477/// operator-flux pipeline grows a `:placement :org` slot, or moving to
1478/// a self-hosted forge under a wholly-owned org name once the
1479/// substrate's forge-gen roadmap graduates past GitHub) without a
1480/// coordinated edit on both sides would silently emit a `feira lock`-
1481/// side `github:<old-org>/<nome>` fallback shorthand while the
1482/// `cluster_bundle`-side `gitrepository.yaml` pointed at the new org's
1483/// `<nome>` — the phase 1.B `feira resolve` walker would probe the
1484/// prior org's git host for a repo that migrated with the org, or vice-
1485/// versa: Flux's `GitRepository` reconciler would loop forever looking
1486/// for an upstream repo the old org handle no longer maps to, the
1487/// dependent `HelmRelease`'s `chart: sourceRef` would never resolve,
1488/// every per-Servico apply would silently come up with the prior
1489/// reconciled state, and the failure would surface at `kubectl describe
1490/// gitrepository` time (the `Status: Stalled` / `Reason: Failed` arm)
1491/// far from the org-migration commit's source.
1492///
1493/// Lifting the literal to one `&'static str` constant closes the drift
1494/// footgun structurally — both consumers read from the same memory, so
1495/// any future org migration reaches both sites by construction and a CI
1496/// build that re-introduces a sibling inline `"pleme-io"` literal trips
1497/// the peer pinning tests at the build-time fail-before-deploy posture
1498/// every prior load-bearing-string lift on this surface
1499/// ([`crate::DEFAULT_NAMESPACE`] a085b26,
1500/// [`crate::DEFAULT_LIBRARY_NAME`] 41438dc,
1501/// [`crate::DEFAULT_SERVICO_PORT`] 1e22add,
1502/// [`DEFAULT_PUBLISH_TAG_PREFIX`] 0a6a602,
1503/// [`DEFAULT_GIT_REMOTE`],
1504/// [`crate::DEFAULT_FLUX_SYSTEM_NAMESPACE`] 7197d38) establishes.
1505///
1506/// Distinct from the [`crate::PLEME_LABEL_PREFIX`] canonical pleme-io
1507/// label-namespace prefix (`"pleme.pleme.io"`, the K8s label-namespace
1508/// axis every substrate-emitted cluster object's `LABEL_APLICACAO` /
1509/// `LABEL_PROGRAM` / `LABEL_CONTRATO` axis shares) — these constants
1510/// sit on separate schema-contract surfaces (the git-host org handle
1511/// vs. the K8s label-namespace prefix) governed by independent rebrand
1512/// cycles, so a git-org rename must not couple the K8s label-namespace
1513/// axis to the git-host axis (or vice-versa). Splitting the two lets
1514/// each schema's future rebrand land independently at its canonical
1515/// const definition without silently coupling the surfaces — same
1516/// "byte-distinct, semantically distinct" discipline the
1517/// [`crate::PLEME_LABEL_PREFIX`] / [`crate::LABEL_APLICACAO`] /
1518/// [`crate::LABEL_PROGRAM`] / [`crate::LABEL_CONTRATO`] set establishes
1519/// on the peer per-K8s-label-namespace canonical-string surface.
1520pub const DEFAULT_PLEME_GIT_ORG: &str = "pleme-io";
1521
1522/// Parse a dep's `:versao` string as a [`semver::VersionReq`].
1523///
1524/// Treats the literal `"*"` as "any version" (semver's wildcard).
1525pub fn parse_requirement(s: &str) -> Result<semver::VersionReq, VersionError> {
1526 if s == "*" {
1527 return Ok(semver::VersionReq::STAR);
1528 }
1529 semver::VersionReq::parse(s).map_err(|e| VersionError::requirement(s, e.to_string()))
1530}
1531
1532#[derive(Debug, Error, PartialEq, Eq)]
1533pub enum VersionError {
1534 #[error("invalid version '{0}': {1}")]
1535 Semver(String, String),
1536 #[error("invalid version requirement '{0}': {1}")]
1537 Requirement(String, String),
1538}
1539
1540// Fold the sole `VersionError::Semver(<into-String-expr>, <into-String-expr>)`
1541// wire-up site on [`CaixaVersion::parse`]'s [`semver::Version::parse`]
1542// `map_err` arm onto one substrate primitive — the paired
1543// `(String, String)` two-slot tuple-newtype [`VersionError::Semver`] on
1544// the [`CaixaVersion`] parser surface, the first of the two variants on
1545// the [`VersionError`] envelope's paired `(String, String)` tuple-newtype
1546// codec-magnitude family (its peer is [`VersionError::Requirement`] on
1547// the sibling [`parse_requirement`] surface). Same discipline the peer
1548// per-variant lifts on [`AplicacaoError`] / [`SupervisorError`] /
1549// [`UpgradeError`] / [`LayoutError`] / [`DepError`] / [`ManifestError`]
1550// / [`LimitsError`] / [`BehaviorError`] / [`DialetoError`] have
1551// converged through the "one substrate primitive per emit-site variant"
1552// ratchet: the sole wire-up site opens the identical
1553// `VersionError::Semver(<into-String-expr>, <into-String-expr>)` block
1554// against the parser-scoped `String` binding (`self.0.clone()`) and the
1555// derived `String` binding (`e.to_string()`) on the failing
1556// [`semver::Version::parse`] arm, so the fold routes the site through
1557// one dispatch on a uniform pair of `impl Into<String>` params,
1558// byte-equal to the pre-lift tuple-newtype construction on the same
1559// arguments. The `impl Into<String>` bound covers both the pre-lift
1560// `String` bindings and any future `&str` binding a downstream consumer
1561// might carry without forcing the caller to spell the `.into()`
1562// conversion at the wire-up site — the same shape the peer
1563// [`LimitsError::empty_byte_size`] / [`LimitsError::empty_duration`] /
1564// [`DialetoError::leitura`] folds carry on the single-slot `(String)`
1565// tuple-newtype cousins of the same tuple-newtype error-envelope family
1566// on the sibling parser surfaces. `#[must_use]` fires a compile warning
1567// at any wire-up that mistakenly discards the constructed error. The
1568// added [`PartialEq`] / [`Eq`] derives on the envelope (peer with the
1569// sibling [`LimitsError`] / [`DialetoError`] / [`DepError`] envelopes
1570// on the same axis) let the fail-before-pass-after byte-equality pins
1571// below trip a de-lift regression at caixa-core test time under
1572// `PartialEq` rather than at a downstream diagnostic shape drift.
1573//
1574// Every future consumer that wants to construct this variant outside
1575// [`CaixaVersion::parse`] (a deferred `feira lint --canonical-versao`
1576// per-caixa admission verb probing each authored top-level `:versao`
1577// value against the same [`semver::Version::parse`] gate, an M4 typed
1578// `mesh.pleme.io/v1alpha1/Servico` CR materializer's per-manifest
1579// admission validator re-checking one edited `:versao` slot against
1580// the [`CaixaVersion::parse`] semver floor, a per-`caixa.lisp` value-
1581// shape pre-emitter probing each declared `:versao` magnitude ahead of
1582// the operator's admit-cycle) now reaches the variant through one call
1583// rather than re-inlining the two-slot tuple-newtype block in lockstep.
1584impl VersionError {
1585 /// Construct a [`VersionError::Semver`] carrying the offending
1586 /// authoring string `value` and the underlying [`semver::Version::parse`]
1587 /// `reason` verbatim in the variant's two-slot tuple-newtype payload.
1588 /// Folds the uniform `Self::Semver(value.into(), reason.into())`
1589 /// tuple-newtype construction onto one substrate primitive so every
1590 /// wire-up on the variant reads through one dispatch rather than the
1591 /// pre-lift open-coded
1592 /// `VersionError::Semver(<into-String-expr>, <into-String-expr>)`
1593 /// block. The paired `impl Into<String>` bounds cover the pre-lift
1594 /// `String` wire-up shape on [`CaixaVersion::parse`]
1595 /// (`self.0.clone()` on the parser-scoped `String` field, `e.to_string()`
1596 /// on the derived `String` from the failing
1597 /// [`semver::Version::parse`] arm) without forcing the caller to
1598 /// spell the conversion at the wire-up site. Peer to the sibling
1599 /// [`VersionError::Requirement`] variant on the [`parse_requirement`]
1600 /// surface — the same `(String, String)` two-slot tuple-newtype axis
1601 /// of the paired [`VersionError`] envelope, but on the `SemVer`
1602 /// version-body parser surface rather than the version-requirement
1603 /// parser surface.
1604 #[must_use]
1605 pub fn semver(value: impl Into<String>, reason: impl Into<String>) -> Self {
1606 Self::Semver(value.into(), reason.into())
1607 }
1608
1609 /// Construct a [`VersionError::Requirement`] carrying the offending
1610 /// authoring string `value` and the underlying
1611 /// [`semver::VersionReq::parse`] `reason` verbatim in the variant's
1612 /// two-slot tuple-newtype payload. Folds the uniform
1613 /// `Self::Requirement(value.into(), reason.into())` tuple-newtype
1614 /// construction onto one substrate primitive so every wire-up on the
1615 /// variant reads through one dispatch rather than the pre-lift open-
1616 /// coded `VersionError::Requirement(<into-String-expr>,
1617 /// <into-String-expr>)` block. Peer to the sibling
1618 /// [`VersionError::semver`] ctor on the [`CaixaVersion::parse`]
1619 /// surface — the same `(String, String)` two-slot tuple-newtype axis
1620 /// of the paired [`VersionError`] envelope, but on the version-
1621 /// requirement parser surface rather than the semver-version-body
1622 /// parser surface. Closes the last un-lifted variant on the
1623 /// [`VersionError`] envelope: every arm now reaches its emit site
1624 /// through one substrate-primitive dispatch, matching the "one
1625 /// substrate primitive per emit-site variant" ratchet the peer per-
1626 /// variant lifts on [`crate::AplicacaoError`] /
1627 /// [`crate::SupervisorError`] / [`crate::UpgradeError`] /
1628 /// [`crate::LayoutError`] / [`crate::DepError`] /
1629 /// [`crate::ManifestError`] / [`crate::LimitsError`] /
1630 /// [`crate::BehaviorError`] / [`crate::DialetoError`] have converged
1631 /// onto.
1632 #[must_use]
1633 pub fn requirement(value: impl Into<String>, reason: impl Into<String>) -> Self {
1634 Self::Requirement(value.into(), reason.into())
1635 }
1636}
1637
1638#[cfg(test)]
1639mod tests {
1640 use super::*;
1641
1642 #[test]
1643 fn version_round_trip() {
1644 let v: CaixaVersion = "1.2.3".into();
1645 assert_eq!(v.as_str(), "1.2.3");
1646 assert_eq!(v.parse().unwrap().to_string(), "1.2.3");
1647 }
1648
1649 #[test]
1650 fn caixa_version_as_str_accessor_is_const_fn() {
1651 // Fail-before-pass-after pin on [`CaixaVersion::as_str`]'s
1652 // `const`-eval-surface posture. The accessor projects the typed
1653 // newtype's inner [`String`] through the `pub const fn`
1654 // [`String::as_str`] (const-stable since Rust 1.87, well within
1655 // the workspace MSRV) — any future accidental downgrade to
1656 // non-`const` fails `as_str_via_const_fn` at caixa-core build
1657 // time with E0015 (`cannot call non-const method`), strictly
1658 // stronger than a runtime `assert!`. Sibling of the peer
1659 // per-M2/M3/universal-axis `String → &str` scalar-accessor
1660 // family pins on the sibling `const`-eval-surface passes
1661 // ([`crate::Caixa::nome`] / [`crate::Caixa::versao`] at the
1662 // top-level manifest, [`crate::aplicacao::Membro::nome`] /
1663 // [`crate::aplicacao::Membro::versao_requirement`] at the M3
1664 // membership axis, [`crate::aplicacao::Entrada::hostname`] /
1665 // [`crate::aplicacao::Entrada::destination`] at the M3 ingress
1666 // axis, [`crate::supervisor::ChildSpec::nome`] /
1667 // [`crate::supervisor::ChildSpec::versao_requirement`] at the
1668 // M2 supervisor-tree axis,
1669 // [`crate::upgrade::UpgradeFromEntry::prior_versao`] at the M2
1670 // upgrade axis, [`crate::dep::Dep::nome`] /
1671 // [`crate::dep::Dep::versao_requirement`] at the dep-graph
1672 // axis, and the peer per-`:contratos` [`crate::aplicacao::WitContract::source`] /
1673 // [`crate::aplicacao::WitContract::destination`] /
1674 // [`crate::aplicacao::WitContract::world_ref`] trio the
1675 // sibling pin at 279823b already anchors).
1676 const fn as_str_via_const_fn(v: &CaixaVersion) -> &str {
1677 v.as_str()
1678 }
1679 for versao in ["0.1.0", "1.2.3-alpha.1", "0.0.0", ""] {
1680 let v: CaixaVersion = versao.into();
1681 assert_eq!(as_str_via_const_fn(&v), v.as_str());
1682 assert_eq!(v.as_str(), versao);
1683 }
1684 }
1685
1686 #[test]
1687 fn star_is_any() {
1688 let r = parse_requirement("*").unwrap();
1689 assert!(r.matches(&"0.1.0".parse().unwrap()));
1690 assert!(r.matches(&"99.0.0".parse().unwrap()));
1691 }
1692
1693 #[test]
1694 fn caret_matches_minor_range() {
1695 let r = parse_requirement("^0.1").unwrap();
1696 assert!(r.matches(&"0.1.0".parse().unwrap()));
1697 assert!(r.matches(&"0.1.99".parse().unwrap()));
1698 assert!(!r.matches(&"0.2.0".parse().unwrap()));
1699 }
1700
1701 #[test]
1702 fn invalid_version_errors() {
1703 let v: CaixaVersion = "not-a-version".into();
1704 assert!(v.parse().is_err());
1705 }
1706
1707 #[test]
1708 fn semver_ctor_matches_tuple_literal_wrap_on_str_binding() {
1709 // Fail-before-pass-after byte-equality pin: the lifted
1710 // [`VersionError::semver`] inherent ctor projects a `&str`
1711 // binding pair through the paired `impl Into<String>` bounds
1712 // byte-equal to the pre-lift open-coded
1713 // `VersionError::Semver(<into-String-expr>, <into-String-expr>)`
1714 // tuple-literal on the same fixture, so any future silent
1715 // regression that swaps `.into()` for a divergent conversion
1716 // (a stray `String::from(str::trim(v))` normalization, a
1717 // parity-lossy `.to_lowercase()` fold, a `Cow<'_, str>` detour)
1718 // trips at caixa-core test time under `PartialEq` rather than
1719 // at a downstream diagnostic-shape drift on a consumer surface.
1720 // Same shape the peer
1721 // [`crate::LimitsError::empty_byte_size_ctor_matches_tuple_literal_wrap_on_str_binding`]
1722 // / [`crate::DialetoError::leitura_ctor_matches_tuple_literal_wrap_on_str_binding`]
1723 // pins carry on the sibling single-slot `(String)` tuple-newtype
1724 // cousins of the same tuple-newtype error-envelope family on the
1725 // sibling parser surfaces.
1726 let value: &str = "not-a-version";
1727 let reason: &str = "unexpected character 'n' while parsing major version number";
1728 assert_eq!(
1729 VersionError::semver(value, reason),
1730 VersionError::Semver(value.to_string(), reason.to_string()),
1731 "generated semver ctor over `&str` bindings must match \
1732 the pre-lift tuple-literal wrap on the same fixture",
1733 );
1734 }
1735
1736 #[test]
1737 fn semver_ctor_matches_tuple_literal_wrap_on_string_binding() {
1738 // Fail-before-pass-after byte-equality pin on the paired owned-
1739 // `String` shape — the actual wire-up shape on
1740 // [`CaixaVersion::parse`] (`self.0.clone()` +
1741 // `e.to_string()`). Peer to the `&str` variant above; refuses
1742 // any future de-lift that inlines a divergent construction on
1743 // the owned-`String` path (a stray `.trim().to_string()`
1744 // normalization on either slot, a swap that routes the ctor
1745 // through the sibling [`VersionError::Requirement`] variant on
1746 // the paired parser surface).
1747 let value: String = String::from("1.2");
1748 let reason: String =
1749 String::from("unexpected end of input while parsing minor version number");
1750 assert_eq!(
1751 VersionError::semver(value.clone(), reason.clone()),
1752 VersionError::Semver(value, reason),
1753 "generated semver ctor over owned-`String` bindings must \
1754 match the pre-lift tuple-literal wrap on the same fixture",
1755 );
1756 }
1757
1758 #[test]
1759 fn parse_semver_error_routes_through_semver_ctor() {
1760 // Fail-before-pass-after routes-through pin: refuses any future
1761 // de-lift of [`CaixaVersion::parse`]'s
1762 // [`semver::Version::parse`] `map_err` arm off the substrate
1763 // primitive. Sweeps three malformed authoring shapes (a bare
1764 // non-numeric, a partial `major.minor` shape, a stray leading
1765 // `v`-prefix that the [`DEFAULT_PUBLISH_TAG_PREFIX`] git-tag
1766 // convention rejects at the version-body slot) through the
1767 // parser and asserts the emitted [`VersionError`] equals the
1768 // ctor-built error verbatim under `PartialEq`, so any future
1769 // swap of the wire-up (an inline `Self::Semver(...)`
1770 // re-inlining, a routing detour through the sibling
1771 // [`VersionError::Requirement`] variant on the paired parser
1772 // surface, a swap of the ordering on the paired arguments)
1773 // trips at caixa-core test time rather than at a downstream
1774 // diagnostic drift on a `feira lint` / operator admission
1775 // callsite.
1776 for bad in ["not-a-version", "1.2", "v0.1.0"] {
1777 let v: CaixaVersion = bad.into();
1778 let err = v
1779 .parse()
1780 .expect_err("malformed versao fixture must fail semver parsing");
1781 let semver_reason = match semver::Version::parse(bad) {
1782 Err(e) => e.to_string(),
1783 Ok(_) => unreachable!(
1784 "fixture `{bad}` is documented as a `SemVer` \
1785 rejection but parsed cleanly — the pin's oracle \
1786 drifted from `semver`'s current shape",
1787 ),
1788 };
1789 assert_eq!(
1790 err,
1791 VersionError::semver(bad, semver_reason),
1792 "CaixaVersion::parse must route its semver `map_err` \
1793 arm through the lifted VersionError::semver ctor on \
1794 the same offending value and semver reason",
1795 );
1796 }
1797 }
1798
1799 #[test]
1800 fn default_git_remote_pins_canonical_origin_byte() {
1801 // Bridge-arm pin: [`DEFAULT_GIT_REMOTE`] resolves to the
1802 // canonical `"origin"` byte today, the same remote-handle every
1803 // `git clone <url>` invocation populates by default and every
1804 // peer `feira` writer-side verb (`feira publish`, `feira deploy
1805 // --apply`, `feira app deploy --apply`) names when it invokes
1806 // `git push <remote> <ref>` against the local clone. Pin the
1807 // literal here (peer with the
1808 // [`DEFAULT_PUBLISH_TAG_PREFIX`] / [`crate::DEFAULT_SERVICO_PORT`]
1809 // / [`crate::DEFAULT_NAMESPACE`] / [`crate::DEFAULT_LIBRARY_NAME`]
1810 // / [`crate::DEFAULT_FLUX_SYSTEM_NAMESPACE`] canonical-literal
1811 // pins on the sibling lifted-constant surfaces) so a future
1812 // remote-naming rebrand surfaces here as a coordinated edit-
1813 // point: the sibling [`caixa-feira`]
1814 // `publish_remote_default_pins_lifted_caixa_core_constant`
1815 // pinning test already pins the equality at the clap-default
1816 // axis; this pin closes the second coordinate of the
1817 // triangle by anchoring the lifted constant's current byte
1818 // to the canonical git-default-remote convention's documented
1819 // shape.
1820 assert_eq!(DEFAULT_GIT_REMOTE, "origin");
1821 }
1822
1823 #[test]
1824 fn default_pleme_git_org_pins_canonical_pleme_io_byte() {
1825 // Bridge-arm pin: [`DEFAULT_PLEME_GIT_ORG`] resolves to the
1826 // canonical `"pleme-io"` GitHub-org-handle today, the same org
1827 // name every peer substrate-side default-git-source consumer
1828 // ([`caixa-feira`]'s `feira lock` `resolve_stub` for the
1829 // per-dep `:fonte`-elided `github:<org>/<nome>` fallback,
1830 // [`caixa-flux`]'s `ClusterBundleOpts::for_caixa` constructor
1831 // for the per-caixa `:repositorio`-elided
1832 // `https://github.com/<org>/<nome>` fallback) fills into its
1833 // per-consumer render/resolve compose site. Pin the literal
1834 // here (peer with the [`DEFAULT_PUBLISH_TAG_PREFIX`] /
1835 // [`DEFAULT_GIT_REMOTE`] canonical-literal pins on the sibling
1836 // lifted-constant surfaces) so a future substrate-side git-org
1837 // migration surfaces here as a coordinated edit-point: both
1838 // sibling consumer sites already thread through the same
1839 // `&'static str`, this pin anchors the lifted constant's
1840 // current byte to the canonical substrate-git-org convention's
1841 // documented shape.
1842 assert_eq!(DEFAULT_PLEME_GIT_ORG, "pleme-io");
1843 }
1844
1845 #[test]
1846 fn requirement_ctor_matches_tuple_literal_wrap_on_str_binding() {
1847 // Fail-before-pass-after byte-equality pin: the lifted
1848 // [`VersionError::requirement`] inherent ctor projects a `&str`
1849 // binding pair through the paired `impl Into<String>` bounds
1850 // byte-equal to the pre-lift open-coded
1851 // `VersionError::Requirement(<into-String-expr>, <into-String-expr>)`
1852 // tuple-literal on the same fixture. Same shape the peer
1853 // [`VersionError::semver_ctor_matches_tuple_literal_wrap_on_str_binding`]
1854 // pin carries on the sibling [`VersionError::Semver`] variant of
1855 // the same `(String, String)` two-slot tuple-newtype envelope.
1856 let value: &str = "not-a-req";
1857 let reason: &str = "unexpected character 'n' while parsing major version number";
1858 assert_eq!(
1859 VersionError::requirement(value, reason),
1860 VersionError::Requirement(value.to_string(), reason.to_string()),
1861 "generated requirement ctor over `&str` bindings must match \
1862 the pre-lift tuple-literal wrap on the same fixture",
1863 );
1864 }
1865
1866 #[test]
1867 fn requirement_ctor_matches_tuple_literal_wrap_on_string_binding() {
1868 // Fail-before-pass-after byte-equality pin on the paired owned-
1869 // `String` shape. Peer to the `&str` variant above; refuses any
1870 // future de-lift that inlines a divergent construction on the
1871 // owned-`String` path (a stray `.trim().to_string()` normalization
1872 // on either slot, a swap that routes the ctor through the sibling
1873 // [`VersionError::Semver`] variant on the paired parser surface,
1874 // an argument-ordering swap on the paired slots).
1875 let value: String = String::from("^bogus");
1876 let reason: String = String::from("unexpected character while parsing requirement");
1877 assert_eq!(
1878 VersionError::requirement(value.clone(), reason.clone()),
1879 VersionError::Requirement(value, reason),
1880 "generated requirement ctor over owned-`String` bindings must \
1881 match the pre-lift tuple-literal wrap on the same fixture",
1882 );
1883 }
1884
1885 #[test]
1886 fn parse_requirement_error_routes_through_requirement_ctor() {
1887 // Fail-before-pass-after routes-through pin: refuses any future
1888 // de-lift of [`parse_requirement`]'s
1889 // [`semver::VersionReq::parse`] `map_err` arm off the substrate
1890 // primitive. Sweeps three malformed authoring shapes (a bare
1891 // non-numeric, a stray operator with no version body, a
1892 // caret-prefixed non-numeric that the [`semver::VersionReq`]
1893 // grammar rejects at the operator-body slot) through the parser
1894 // and asserts the emitted [`VersionError`] equals the ctor-built
1895 // error verbatim under `PartialEq`, so any future swap of the
1896 // wire-up (an inline `Self::Requirement(...)` re-inlining, a
1897 // routing detour through the sibling [`VersionError::Semver`]
1898 // variant on the paired parser surface, an argument-ordering
1899 // swap on the paired slots) trips at caixa-core test time rather
1900 // than at a downstream diagnostic drift on a `feira lock` /
1901 // resolver admission callsite. The `"*"` wildcard short-circuit
1902 // is deliberately excluded from the sweep — it returns
1903 // [`semver::VersionReq::STAR`] before reaching the parser arm.
1904 for bad in ["not-a-req", "^", "^bogus"] {
1905 let err = parse_requirement(bad)
1906 .expect_err("malformed requirement fixture must fail parsing");
1907 let semver_reason = match semver::VersionReq::parse(bad) {
1908 Err(e) => e.to_string(),
1909 Ok(_) => unreachable!(
1910 "fixture `{bad}` is documented as a `VersionReq` \
1911 rejection but parsed cleanly — the pin's oracle \
1912 drifted from `semver`'s current shape",
1913 ),
1914 };
1915 assert_eq!(
1916 err,
1917 VersionError::requirement(bad, semver_reason),
1918 "parse_requirement must route its `map_err` arm through \
1919 the lifted VersionError::requirement ctor on the same \
1920 offending value and semver reason",
1921 );
1922 }
1923 }
1924
1925 #[test]
1926 fn default_publish_tag_prefix_pins_canonical_v_byte() {
1927 // Bridge-arm pin: [`DEFAULT_PUBLISH_TAG_PREFIX`] resolves to the
1928 // canonical Zig-style `"v"` byte today, the same prefix every
1929 // peer doc-comment on the typed `:versao` surfaces (the
1930 // top-level `:versao` `validate_versao` cascade at
1931 // caixa-core/src/manifest.rs:646, the four sibling per-axis
1932 // `:versao` requirement gates that name the publish-side
1933 // `v<versao>` tag inline in their bodies) cites as the
1934 // canonical convention. Pin the literal here (peer with the
1935 // [`crate::DEFAULT_SERVICO_PORT`] / [`crate::DEFAULT_NAMESPACE`]
1936 // / [`crate::DEFAULT_LIBRARY_NAME`] canonical-literal pins on
1937 // the sibling lifted-constant surfaces) so a future rebrand of
1938 // the constant surfaces here as a coordinated edit-point: both
1939 // sibling pinning tests on the two consumer crates
1940 // ([`caixa-feira`] `publish_prefix_default_pins_lifted_caixa_core_constant`,
1941 // [`caixa-flux`] `cluster_bundle_default_git_tag_uses_lifted_caixa_core_prefix`)
1942 // already pin the equality at the consumer-default axis; this
1943 // pin closes the third coordinate of the triangle by anchoring
1944 // the lifted constant's current byte to the canonical Zig-style
1945 // convention's documented shape.
1946 assert_eq!(DEFAULT_PUBLISH_TAG_PREFIX, "v");
1947 }
1948
1949 #[test]
1950 fn caixa_version_as_ref_str_routes_through_as_str_accessor() {
1951 // Fail-before-pass-after byte-parity pin on the lifted
1952 // `impl AsRef<str> for CaixaVersion` — asserts the standard-
1953 // library trait impl and the substrate-primitive
1954 // [`CaixaVersion::as_str`] `pub const fn` accessor resolve to
1955 // the same `&str` per instance, so any future silent detour
1956 // that routes the impl through a divergent projection (a
1957 // `Cow<'_, str>` intermediate, a stray `.to_lowercase()`
1958 // normalization, a swap onto a per-arm inline `&self.0.as_str()`
1959 // re-inlining, a swap onto a divergent [`String::trim`]
1960 // fold) trips at caixa-core test time under `PartialEq`
1961 // rather than at a downstream `impl AsRef<str>`-bound
1962 // consumer's silent split. Sweeps four authoring shapes (a
1963 // canonical release version, a pre-release build-metadata
1964 // version, the zero-version canonical unset baseline, and
1965 // the empty-string byte the caller-side default-construct
1966 // path composes) so every non-degenerate arm of the wrapped
1967 // `String` storage is covered. Peer of the sibling
1968 // [`caixa_version_as_str_accessor_is_const_fn`] const-eval
1969 // pin on the same [`CaixaVersion::as_str`] primitive — the
1970 // two pins together cover the const-eval axis (the pin above)
1971 // and the trait-projection axis (this pin) of the same
1972 // substrate-primitive scalar accessor.
1973 for versao in ["0.1.0", "1.2.3-alpha.1", "0.0.0", ""] {
1974 let v: CaixaVersion = versao.into();
1975 assert_eq!(
1976 <CaixaVersion as AsRef<str>>::as_ref(&v),
1977 v.as_str(),
1978 "AsRef<str> impl must byte-equal CaixaVersion::as_str \
1979 on the same instance — divergence signals a silent \
1980 detour off the substrate-primitive accessor",
1981 );
1982 assert_eq!(
1983 <CaixaVersion as AsRef<str>>::as_ref(&v),
1984 versao,
1985 "AsRef<str> impl must byte-equal the pre-lift wrapped \
1986 String storage on round-trip through the From<&str> \
1987 constructor — divergence signals a normalization \
1988 detour on either the constructor or the accessor",
1989 );
1990 }
1991 }
1992
1993 #[test]
1994 fn caixa_version_as_ref_str_routes_through_display_via_shared_accessor() {
1995 // Fail-before-pass-after byte-parity pin on the three-path
1996 // convergence discipline the substrate primitive now carries
1997 // on the `&str`-projection axis: `<CaixaVersion as
1998 // AsRef<str>>::as_ref(&v)` (the newly lifted impl),
1999 // `format!("{v}")` (the pre-existing [`fmt::Display`] impl),
2000 // and `v.as_str()` (the substrate-primitive `pub const fn`
2001 // accessor both trait impls delegate through) must resolve to
2002 // the same byte-string on every instance. Refuses any future
2003 // divergence between the two trait impls (a stray
2004 // [`fmt::Display::fmt`] rewrite that inlines
2005 // `f.write_str(&self.0)` on the wrapped `String` directly,
2006 // bypassing the shared accessor; a hypothetical `AsRef<str>`
2007 // rewrite that inlines the same `&self.0` field-access) that
2008 // would silently split the two projection paths of the same
2009 // typed newtype. Mirrors the sibling three-path-convergence
2010 // discipline the peer [`RestartStrategy`] typed enum carries
2011 // on its `Display` / `as_str` / `Serialize` triple (aplicacao.rs
2012 // pin `restart_strategy_display_matches_serialized_wire_byte_string`).
2013 for versao in ["0.1.0", "1.2.3-alpha.1", ""] {
2014 let v: CaixaVersion = versao.into();
2015 let via_as_ref: &str = <CaixaVersion as AsRef<str>>::as_ref(&v);
2016 let via_display: String = format!("{v}");
2017 let via_accessor: &str = v.as_str();
2018 assert_eq!(via_as_ref, via_accessor);
2019 assert_eq!(via_display, via_accessor);
2020 assert_eq!(via_as_ref, via_display.as_str());
2021 }
2022 }
2023
2024 #[test]
2025 fn caixa_version_borrow_str_routes_through_as_str_accessor() {
2026 // Fail-before-pass-after byte-parity pin on the lifted
2027 // `impl std::borrow::Borrow<str> for CaixaVersion` — asserts the
2028 // standard-library trait impl and the substrate-primitive
2029 // [`CaixaVersion::as_str`] `pub const fn` accessor resolve to
2030 // the same `&str` per instance, so any future silent detour
2031 // that routes the impl through a divergent projection (a
2032 // `Cow<'_, str>` intermediate, a stray `.to_lowercase()`
2033 // normalization, a swap onto a per-arm inline `&self.0.as_str()`
2034 // re-inlining that bypasses the shared accessor) trips at
2035 // caixa-core test time under `PartialEq` rather than at a
2036 // downstream `Borrow<str>`-bound collection API's silent
2037 // hash-mismatch on the load-bearing HashMap-key axis. Peer of
2038 // the sibling
2039 // [`caixa_version_as_ref_str_routes_through_as_str_accessor`]
2040 // byte-parity pin on the paired [`AsRef<str>`] impl — both cover
2041 // the borrow-projection axis of the same substrate primitive.
2042 use std::borrow::Borrow;
2043 for versao in ["0.1.0", "1.2.3-alpha.1", "0.0.0", ""] {
2044 let v: CaixaVersion = versao.into();
2045 assert_eq!(
2046 <CaixaVersion as Borrow<str>>::borrow(&v),
2047 v.as_str(),
2048 "Borrow<str> impl must byte-equal CaixaVersion::as_str \
2049 on the same instance — divergence signals a silent \
2050 detour off the substrate-primitive accessor",
2051 );
2052 assert_eq!(
2053 <CaixaVersion as Borrow<str>>::borrow(&v),
2054 versao,
2055 "Borrow<str> impl must byte-equal the pre-lift wrapped \
2056 String storage on round-trip through the From<&str> \
2057 constructor",
2058 );
2059 }
2060 }
2061
2062 #[test]
2063 fn caixa_version_borrow_str_and_as_ref_str_agree_on_every_shape() {
2064 // Fail-before-pass-after cross-axis partition pin on the two
2065 // trait impls on the same borrow-projection axis: the lifted
2066 // [`std::borrow::Borrow<str>`] impl (this commit) and the paired
2067 // [`AsRef<str>`] impl (a086 lift) must resolve to the same `&str`
2068 // per instance, both routing through the shared substrate-
2069 // primitive [`CaixaVersion::as_str`] accessor. Refuses any future
2070 // silent split between the two trait impls (a stray
2071 // [`AsRef::as_ref`] rewrite that inlines `&self.0.as_str()` on
2072 // the wrapped [`String`] directly, bypassing the shared
2073 // accessor; a hypothetical [`Borrow::borrow`] rewrite that
2074 // inlines the same `&self.0` field-access) that would silently
2075 // split the two projection paths of the same typed newtype and
2076 // break the [`std::borrow::Borrow`] safety contract's
2077 // "hash-agrees on the borrowed view" invariant the collection
2078 // APIs rely on. Mirrors the sibling three-path convergence
2079 // discipline the peer
2080 // [`caixa_version_as_ref_str_routes_through_display_via_shared_accessor`]
2081 // pin carries on the `AsRef<str>` / `Display` / `as_str` triple.
2082 use std::borrow::Borrow;
2083 for versao in ["0.1.0", "1.2.3-alpha.1", "0.0.0", ""] {
2084 let v: CaixaVersion = versao.into();
2085 let via_borrow: &str = <CaixaVersion as Borrow<str>>::borrow(&v);
2086 let via_as_ref: &str = <CaixaVersion as AsRef<str>>::as_ref(&v);
2087 let via_accessor: &str = v.as_str();
2088 assert_eq!(via_borrow, via_accessor);
2089 assert_eq!(via_as_ref, via_accessor);
2090 assert_eq!(via_borrow, via_as_ref);
2091 }
2092 }
2093
2094 #[test]
2095 fn caixa_version_borrow_str_enables_hashmap_lookup_by_borrowed_key() {
2096 // Fail-before-pass-after contract-witness pin on the
2097 // [`std::borrow::Borrow<str>`] safety contract: a
2098 // [`std::collections::HashMap`] keyed by owned [`CaixaVersion`]
2099 // must resolve `.get::<str>("<versao>")` probes through the
2100 // borrowed `&str` view of a stored key to the same slot, and
2101 // (`String::hash` calls `str::hash` on bytes, and the
2102 // [`CaixaVersion`] derived [`Hash`] impl hashes the wrapped
2103 // [`String`] field) the borrowed and owned hash must agree on
2104 // every fixture. Refuses any future silent regression that would
2105 // break the hash-agrees invariant (a
2106 // [`Hash for CaixaVersion`] hand-written impl that diverges from
2107 // the derived shape, a [`Borrow<str>::borrow`] rewrite that
2108 // routes through a normalization detour, an `Eq` hand-written
2109 // impl that diverges from field-wise equality) —
2110 // [`HashMap::get<Q>`] would return [`None`] on a key that
2111 // structurally lives in the map, which is the exact silent
2112 // failure the [`std::borrow::Borrow`] documented safety contract
2113 // rules out. The load-bearing use-case this impl was added for:
2114 // per-`:versao` collection APIs must be probed by borrowed
2115 // `&str` without a per-probe [`CaixaVersion::from(&str)`]
2116 // allocation.
2117 use std::collections::HashMap;
2118 let mut map: HashMap<CaixaVersion, u32> = HashMap::new();
2119 for (i, versao) in ["0.1.0", "1.2.3-alpha.1", "0.0.0", ""].iter().enumerate() {
2120 let key: CaixaVersion = (*versao).into();
2121 map.insert(key, u32::try_from(i).unwrap());
2122 }
2123 for (i, versao) in ["0.1.0", "1.2.3-alpha.1", "0.0.0", ""].iter().enumerate() {
2124 let hit = map.get(*versao).unwrap_or_else(|| {
2125 panic!(
2126 "HashMap<CaixaVersion, _>::get(&str) must reach the \
2127 slot inserted under CaixaVersion::from({versao:?}) \
2128 through the Borrow<str> bound — a miss signals the \
2129 borrowed-vs-owned hash-agrees invariant broke",
2130 )
2131 });
2132 assert_eq!(*hit, u32::try_from(i).unwrap());
2133 }
2134 assert!(
2135 !map.contains_key("does-not-exist"),
2136 "HashMap<CaixaVersion, _>::contains_key(&str) on an absent \
2137 key must return false, not accidentally hash-collide onto \
2138 a stored slot — the miss path must respect the same \
2139 invariant as the hit path",
2140 );
2141 }
2142
2143 #[test]
2144 fn caixa_version_from_into_owned_string_returns_wrapped_body() {
2145 // Fail-before-pass-after byte-parity pin on the lifted
2146 // `impl From<CaixaVersion> for String` — asserts the owned-input
2147 // reverse-projection routes the wrapper's own heap allocation
2148 // through verbatim (no re-copy, no normalization detour) so
2149 // `String::from(v)` returns the same bytes `v.as_str()`
2150 // borrows. Refuses any future silent detour that would swap
2151 // the move on `v.0` for an allocating `.as_str().to_owned()` /
2152 // `.to_string()` cascade (the pre-lift compose shape), a stray
2153 // `.trim().to_owned()` normalization, or a routing through the
2154 // sibling [`fmt::Display`] emitter that would introduce a
2155 // formatter round-trip.
2156 for versao in ["0.1.0", "1.2.3-alpha.1", "0.0.0", ""] {
2157 let v: CaixaVersion = versao.into();
2158 let expected = v.as_str().to_owned();
2159 let owned: String = String::from(v);
2160 assert_eq!(
2161 owned, expected,
2162 "String::from(v) must return the wrapper's own bytes verbatim",
2163 );
2164 assert_eq!(
2165 owned, versao,
2166 "String::from(v) must round-trip byte-equal through the From<&str> constructor",
2167 );
2168 }
2169 }
2170
2171 #[test]
2172 fn caixa_version_from_into_owned_string_and_as_str_agree_on_every_shape() {
2173 // Fail-before-pass-after cross-axis partition pin: the owned-
2174 // input [`From<CaixaVersion> for String`] reverse projection
2175 // and the borrowed [`AsRef<str>`] projection resolve to the
2176 // same bytes on every instance, and the paired forward
2177 // [`From<String> for CaixaVersion`] constructor closes the
2178 // `Self → String → Self` round-trip by construction. Refuses
2179 // any future silent split between the owned-move reverse axis
2180 // and the borrowed-clone AsRef axis (a stray normalization on
2181 // one path only) that would let `String::from(v)` and
2182 // `v.as_ref::<str>()` diverge on the same instance.
2183 for versao in ["0.1.0", "1.2.3-alpha.1", "0.0.0", ""] {
2184 let v: CaixaVersion = versao.into();
2185 let via_as_ref: String = <CaixaVersion as AsRef<str>>::as_ref(&v).to_owned();
2186 let via_to_string: String = v.to_string();
2187 let via_from: String = String::from(v.clone());
2188 assert_eq!(via_from, via_as_ref);
2189 assert_eq!(via_from, via_to_string);
2190 let round_trip: CaixaVersion = via_from.clone().into();
2191 assert_eq!(round_trip, v);
2192 }
2193 }
2194
2195 #[test]
2196 fn caixa_version_from_borrowed_into_owned_string_routes_through_as_str_accessor() {
2197 // Fail-before-pass-after byte-parity pin on the lifted
2198 // `impl From<&CaixaVersion> for String` — asserts the
2199 // borrowed-input reverse projection allocates a fresh
2200 // [`String`] whose bytes byte-equal the substrate-primitive
2201 // [`CaixaVersion::as_str`] accessor on the same instance,
2202 // preserving the source [`CaixaVersion`] intact (no move-out).
2203 // Refuses any future silent detour that would route the impl
2204 // through a divergent projection (a stray normalization step,
2205 // a swap onto the sibling [`fmt::Display`]-routed
2206 // [`ToString::to_string`] surface, a re-inlining that
2207 // dereferences `&self.0` outside the shared accessor).
2208 for versao in ["0.1.0", "1.2.3-alpha.1", "0.0.0", ""] {
2209 let v: CaixaVersion = versao.into();
2210 let via_borrowed: String = String::from(&v);
2211 assert_eq!(
2212 via_borrowed,
2213 v.as_str(),
2214 "String::from(&v) must byte-equal CaixaVersion::as_str",
2215 );
2216 // The borrowed-input impl must not move out of the source.
2217 assert_eq!(
2218 v.as_str(),
2219 versao,
2220 "source CaixaVersion must survive borrowed-input projection"
2221 );
2222 }
2223 }
2224
2225 #[test]
2226 fn caixa_version_from_owned_and_borrowed_into_string_agree_on_every_shape() {
2227 // Fail-before-pass-after cross-axis partition pin: the paired
2228 // owned-input [`From<CaixaVersion> for String`] and
2229 // borrowed-input [`From<&CaixaVersion> for String`] impls
2230 // resolve to the same bytes on every instance, closing the
2231 // "owned-input move vs. borrowed-input clone" bifurcation on
2232 // the same wrapped body. Refuses any future silent split
2233 // between the two corners (a normalization on one path only, a
2234 // divergent routing that would let `String::from(v.clone())`
2235 // and `String::from(&v)` disagree on the same body).
2236 for versao in ["0.1.0", "1.2.3-alpha.1", "0.0.0", ""] {
2237 let v: CaixaVersion = versao.into();
2238 let via_borrowed: String = String::from(&v);
2239 let via_owned: String = String::from(v.clone());
2240 assert_eq!(via_owned, via_borrowed);
2241 assert_eq!(via_borrowed, versao);
2242 }
2243 }
2244
2245 #[test]
2246 fn caixa_version_from_into_owned_cow_str_returns_owned_wrapped_body() {
2247 // Fail-before-pass-after byte-parity + [`Cow::Owned`]-arm pin
2248 // on the lifted `impl From<CaixaVersion> for
2249 // std::borrow::Cow<'static, str>` — asserts the owned-input
2250 // reverse projection routes the wrapper's own heap allocation
2251 // through `Cow::Owned(v.0)` verbatim (no re-copy, no
2252 // normalization detour, no `Cow::Borrowed` misclassification
2253 // that would demand a `&'static str` the runtime wrapper cannot
2254 // carry), so the emitted [`Cow`] byte-equals the substrate-
2255 // primitive [`CaixaVersion::as_str`] accessor on the same
2256 // instance and round-trips byte-equal through the paired
2257 // forward [`From<String> for CaixaVersion`] constructor.
2258 // Refuses any future silent detour: a swap of the move on
2259 // `v.0` for an allocating `.as_str().to_owned()` cascade (the
2260 // pre-lift compose shape would double-allocate a fresh
2261 // intermediary [`String`] on the way to the same
2262 // [`Cow::Owned`] arm), a stray `.trim().to_owned()`
2263 // normalization, or a mis-routing through
2264 // [`Cow::Borrowed`] on a non-`'static` byte-string that would
2265 // not type-check.
2266 use std::borrow::Cow;
2267 for versao in ["0.1.0", "1.2.3-alpha.1", "0.0.0", ""] {
2268 let v: CaixaVersion = versao.into();
2269 let expected = v.as_str().to_owned();
2270 let cow: Cow<'static, str> = Cow::from(v.clone());
2271 assert!(
2272 matches!(cow, Cow::Owned(_)),
2273 "From<CaixaVersion> for Cow<'static, str> must land on \
2274 the Cow::Owned arm — a runtime String wrapper cannot \
2275 promise the 'static lifetime the Cow::Borrowed arm \
2276 requires",
2277 );
2278 assert_eq!(
2279 cow.as_ref(),
2280 expected,
2281 "Cow::from(v) must return the wrapper's own bytes verbatim",
2282 );
2283 let round_trip: CaixaVersion = cow.into_owned().into();
2284 assert_eq!(
2285 round_trip, v,
2286 "Cow::from(v).into_owned() must round-trip byte-equal \
2287 through the From<String> constructor",
2288 );
2289 }
2290 }
2291
2292 #[test]
2293 fn caixa_version_from_into_owned_cow_str_and_string_agree_on_every_shape() {
2294 // Fail-before-pass-after cross-axis partition pin: the owned-
2295 // input [`From<CaixaVersion> for Cow<'static, str>`] reverse
2296 // projection and the paired owned-input
2297 // [`From<CaixaVersion> for String`] reverse projection resolve
2298 // to the same bytes on every instance, and both agree with the
2299 // borrowed [`AsRef<str>`] surface on the same wrapped body.
2300 // Refuses any future silent split between the two owned-input
2301 // reverse-projection axes (a stray normalization on one path
2302 // only, a divergent routing that would let
2303 // `Cow::from(v.clone())` and `String::from(v.clone())` disagree
2304 // on the same body) that would silently split the same-shape
2305 // owned-move discipline across the two reverse-projection
2306 // targets.
2307 use std::borrow::Cow;
2308 for versao in ["0.1.0", "1.2.3-alpha.1", "0.0.0", ""] {
2309 let v: CaixaVersion = versao.into();
2310 let via_string: String = String::from(v.clone());
2311 let via_cow: Cow<'static, str> = Cow::from(v.clone());
2312 let via_as_ref: &str = <CaixaVersion as AsRef<str>>::as_ref(&v);
2313 assert_eq!(via_cow.as_ref(), via_string.as_str());
2314 assert_eq!(via_cow.as_ref(), via_as_ref);
2315 assert_eq!(via_cow.as_ref(), versao);
2316 }
2317 }
2318
2319 #[test]
2320 fn caixa_version_from_borrowed_into_owned_cow_str_routes_through_as_str_accessor() {
2321 // Fail-before-pass-after byte-parity + [`Cow::Owned`]-arm pin
2322 // on the lifted `impl From<&CaixaVersion> for
2323 // std::borrow::Cow<'static, str>` — asserts the borrowed-input
2324 // reverse projection allocates a fresh [`Cow::Owned`] whose
2325 // bytes byte-equal the substrate-primitive
2326 // [`CaixaVersion::as_str`] accessor on the same instance,
2327 // preserving the source [`CaixaVersion`] intact (no move-out).
2328 // Refuses any future silent detour that would route the impl
2329 // through a divergent projection (a stray normalization step,
2330 // a mis-routing onto [`Cow::Borrowed`] on a non-`'static`
2331 // byte-string that would not type-check, a re-inlining that
2332 // dereferences `&self.0` outside the shared accessor).
2333 use std::borrow::Cow;
2334 for versao in ["0.1.0", "1.2.3-alpha.1", "0.0.0", ""] {
2335 let v: CaixaVersion = versao.into();
2336 let via_borrowed: Cow<'static, str> = Cow::from(&v);
2337 assert!(
2338 matches!(via_borrowed, Cow::Owned(_)),
2339 "From<&CaixaVersion> for Cow<'static, str> must land on \
2340 the Cow::Owned arm — a runtime String wrapper cannot \
2341 promise the 'static lifetime the Cow::Borrowed arm \
2342 requires",
2343 );
2344 assert_eq!(
2345 via_borrowed.as_ref(),
2346 v.as_str(),
2347 "Cow::from(&v) must byte-equal CaixaVersion::as_str",
2348 );
2349 // The borrowed-input impl must not move out of the source.
2350 assert_eq!(
2351 v.as_str(),
2352 versao,
2353 "source CaixaVersion must survive borrowed-input projection",
2354 );
2355 }
2356 }
2357
2358 #[test]
2359 fn caixa_version_from_owned_and_borrowed_into_cow_str_agree_on_every_shape() {
2360 // Fail-before-pass-after cross-axis partition pin: the paired
2361 // owned-input [`From<CaixaVersion> for Cow<'static, str>`] and
2362 // borrowed-input [`From<&CaixaVersion> for Cow<'static, str>`]
2363 // impls resolve to the same bytes on every instance, closing
2364 // the "owned-input move vs. borrowed-input clone" bifurcation
2365 // on the same wrapped body through the [`Cow<'static, str>`]
2366 // axis. Refuses any future silent split between the two
2367 // corners (a normalization on one path only, a divergent
2368 // routing that would let `Cow::from(v.clone())` and
2369 // `Cow::from(&v)` disagree on the same body). Both corners
2370 // must land on [`Cow::Owned`] — the runtime wrapper's storage
2371 // rules out the borrowed arm on both input shapes alike.
2372 use std::borrow::Cow;
2373 for versao in ["0.1.0", "1.2.3-alpha.1", "0.0.0", ""] {
2374 let v: CaixaVersion = versao.into();
2375 let via_borrowed: Cow<'static, str> = Cow::from(&v);
2376 let via_owned: Cow<'static, str> = Cow::from(v.clone());
2377 assert!(matches!(via_borrowed, Cow::Owned(_)));
2378 assert!(matches!(via_owned, Cow::Owned(_)));
2379 assert_eq!(via_owned.as_ref(), via_borrowed.as_ref());
2380 assert_eq!(via_borrowed.as_ref(), versao);
2381 }
2382 }
2383
2384 #[test]
2385 fn caixa_version_from_into_owned_box_str_returns_wrapped_body() {
2386 // Fail-before-pass-after byte-parity pin on the lifted
2387 // `impl From<CaixaVersion> for Box<str>` — asserts the owned-
2388 // input reverse projection routes the wrapper's own heap
2389 // allocation through [`String::into_boxed_str`] verbatim (no
2390 // re-copy of the underlying bytes on the fixed-capacity path;
2391 // `String::into_boxed_str` reuses the same `Vec<u8>` buffer
2392 // when length matches capacity), so `Box::<str>::from(v)`
2393 // returns the same bytes `v.as_str()` borrows and round-trips
2394 // byte-equal through the paired forward
2395 // [`From<String> for CaixaVersion`] constructor closing the
2396 // two-way `Self → Box<str> → Self` cycle by construction.
2397 // Refuses any future silent detour that would swap
2398 // `v.0.into_boxed_str()` for an allocating
2399 // `.as_str().to_owned().into_boxed_str()` cascade (the pre-lift
2400 // compose shape would double-allocate a fresh intermediary
2401 // [`String`] on the way to the same [`Box<str>`] slot), a
2402 // stray `.trim().to_owned().into_boxed_str()` normalization,
2403 // or a routing through the sibling [`fmt::Display`] emitter
2404 // that would introduce a formatter round-trip.
2405 for versao in ["0.1.0", "1.2.3-alpha.1", "0.0.0", ""] {
2406 let v: CaixaVersion = versao.into();
2407 let expected = v.as_str().to_owned();
2408 let boxed: Box<str> = Box::<str>::from(v.clone());
2409 assert_eq!(
2410 boxed.as_ref(),
2411 expected.as_str(),
2412 "Box::<str>::from(v) must return the wrapper's own bytes verbatim",
2413 );
2414 let round_trip: CaixaVersion = boxed.into_string().into();
2415 assert_eq!(
2416 round_trip, v,
2417 "Box::<str>::from(v).into_string() must round-trip byte-equal \
2418 through the From<String> constructor",
2419 );
2420 }
2421 }
2422
2423 #[test]
2424 fn caixa_version_from_into_owned_box_str_and_string_agree_on_every_shape() {
2425 // Fail-before-pass-after cross-axis partition pin: the owned-
2426 // input [`From<CaixaVersion> for Box<str>`] reverse projection
2427 // and the paired owned-input [`From<CaixaVersion> for String`]
2428 // and [`From<CaixaVersion> for Cow<'static, str>`] reverse
2429 // projections resolve to the same bytes on every instance, and
2430 // all three agree with the borrowed [`AsRef<str>`] surface on
2431 // the same wrapped body. Refuses any future silent split
2432 // between the three owned-input reverse-projection axes (a
2433 // stray normalization on one path only, a divergent routing
2434 // that would let `Box::<str>::from(v.clone())`,
2435 // `String::from(v.clone())`, and `Cow::from(v.clone())`
2436 // disagree on the same body) that would silently split the
2437 // same-shape owned-move discipline across the three
2438 // reverse-projection targets.
2439 use std::borrow::Cow;
2440 for versao in ["0.1.0", "1.2.3-alpha.1", "0.0.0", ""] {
2441 let v: CaixaVersion = versao.into();
2442 let via_string: String = String::from(v.clone());
2443 let via_cow: Cow<'static, str> = Cow::from(v.clone());
2444 let via_box: Box<str> = Box::<str>::from(v.clone());
2445 let via_as_ref: &str = <CaixaVersion as AsRef<str>>::as_ref(&v);
2446 assert_eq!(via_box.as_ref(), via_string.as_str());
2447 assert_eq!(via_box.as_ref(), via_cow.as_ref());
2448 assert_eq!(via_box.as_ref(), via_as_ref);
2449 assert_eq!(via_box.as_ref(), versao);
2450 }
2451 }
2452
2453 #[test]
2454 fn caixa_version_from_borrowed_into_owned_box_str_routes_through_as_str_accessor() {
2455 // Fail-before-pass-after byte-parity pin on the lifted
2456 // `impl From<&CaixaVersion> for Box<str>` — asserts the
2457 // borrowed-input reverse projection allocates a fresh
2458 // [`Box<str>`] whose bytes byte-equal the substrate-primitive
2459 // [`CaixaVersion::as_str`] accessor on the same instance,
2460 // preserving the source [`CaixaVersion`] intact (no move-out).
2461 // Refuses any future silent detour that would route the impl
2462 // through a divergent projection (a stray normalization step,
2463 // a swap onto the sibling [`fmt::Display`]-routed
2464 // [`ToString::to_string`] surface followed by
2465 // `.into_boxed_str()`, a re-inlining that dereferences
2466 // `&self.0` outside the shared accessor).
2467 for versao in ["0.1.0", "1.2.3-alpha.1", "0.0.0", ""] {
2468 let v: CaixaVersion = versao.into();
2469 let via_borrowed: Box<str> = Box::<str>::from(&v);
2470 assert_eq!(
2471 via_borrowed.as_ref(),
2472 v.as_str(),
2473 "Box::<str>::from(&v) must byte-equal CaixaVersion::as_str",
2474 );
2475 // The borrowed-input impl must not move out of the source.
2476 assert_eq!(
2477 v.as_str(),
2478 versao,
2479 "source CaixaVersion must survive borrowed-input projection",
2480 );
2481 }
2482 }
2483
2484 #[test]
2485 fn caixa_version_from_owned_and_borrowed_into_box_str_agree_on_every_shape() {
2486 // Fail-before-pass-after cross-corner partition pin: the paired
2487 // owned-input [`From<CaixaVersion> for Box<str>`] and
2488 // borrowed-input [`From<&CaixaVersion> for Box<str>`] impls
2489 // resolve to the same bytes on every instance, closing the
2490 // "owned-input move vs. borrowed-input clone" bifurcation on
2491 // the same wrapped body through the [`Box<str>`] axis. Refuses
2492 // any future silent split between the two corners (a
2493 // normalization on one path only, a divergent routing that
2494 // would let `Box::<str>::from(v.clone())` and
2495 // `Box::<str>::from(&v)` disagree on the same body).
2496 for versao in ["0.1.0", "1.2.3-alpha.1", "0.0.0", ""] {
2497 let v: CaixaVersion = versao.into();
2498 let via_borrowed: Box<str> = Box::<str>::from(&v);
2499 let via_owned: Box<str> = Box::<str>::from(v.clone());
2500 assert_eq!(via_owned.as_ref(), via_borrowed.as_ref());
2501 assert_eq!(via_borrowed.as_ref(), versao);
2502 }
2503 }
2504
2505 #[test]
2506 fn caixa_version_from_into_owned_arc_str_returns_wrapped_body() {
2507 // Fail-before-pass-after byte-parity pin on the lifted
2508 // `impl From<CaixaVersion> for std::sync::Arc<str>` — asserts
2509 // the owned-input reverse projection routes the wrapper's own
2510 // [`String`] body through [`std::sync::Arc::<str>::from`]
2511 // verbatim (one heap allocation of the atomically-refcounted
2512 // slab, no intermediary [`String`] or [`Box<str>`] on the
2513 // owned-input path), so `Arc::<str>::from(v)` returns the same
2514 // bytes `v.as_str()` borrows and round-trips byte-equal through
2515 // the paired forward [`From<String> for CaixaVersion`]
2516 // constructor closing the two-way `Self → Arc<str> → Self`
2517 // cycle by construction. Refuses any future silent detour that
2518 // would swap `Arc::<str>::from(v.0)` for an allocating
2519 // `.as_str().to_owned().into()` cascade (the pre-lift compose
2520 // shape would double-allocate a fresh intermediary [`String`]
2521 // on the way to the same [`Arc<str>`] slot), a stray
2522 // `.trim().to_owned().into()` normalization, or a routing
2523 // through the sibling [`fmt::Display`] emitter that would
2524 // introduce a formatter round-trip.
2525 use std::sync::Arc;
2526 for versao in ["0.1.0", "1.2.3-alpha.1", "0.0.0", ""] {
2527 let v: CaixaVersion = versao.into();
2528 let expected = v.as_str().to_owned();
2529 let arced: Arc<str> = Arc::<str>::from(v.clone());
2530 assert_eq!(
2531 arced.as_ref(),
2532 expected.as_str(),
2533 "Arc::<str>::from(v) must return the wrapper's own bytes verbatim",
2534 );
2535 let round_trip: CaixaVersion = arced.as_ref().to_owned().into();
2536 assert_eq!(
2537 round_trip, v,
2538 "Arc::<str>::from(v) must round-trip byte-equal through \
2539 the From<String> constructor",
2540 );
2541 }
2542 }
2543
2544 #[test]
2545 fn caixa_version_from_into_owned_arc_str_and_string_agree_on_every_shape() {
2546 // Fail-before-pass-after cross-axis partition pin: the owned-
2547 // input [`From<CaixaVersion> for std::sync::Arc<str>`] reverse
2548 // projection and the paired owned-input
2549 // [`From<CaixaVersion> for String`],
2550 // [`From<CaixaVersion> for Cow<'static, str>`], and
2551 // [`From<CaixaVersion> for Box<str>`] reverse projections
2552 // resolve to the same bytes on every instance, and all four
2553 // agree with the borrowed [`AsRef<str>`] surface on the same
2554 // wrapped body. Refuses any future silent split between the
2555 // four owned-input reverse-projection axes (a stray
2556 // normalization on one path only, a divergent routing that
2557 // would let `Arc::<str>::from(v.clone())`,
2558 // `Box::<str>::from(v.clone())`, `String::from(v.clone())`,
2559 // and `Cow::from(v.clone())` disagree on the same body) that
2560 // would silently split the same-shape owned-move discipline
2561 // across the four reverse-projection targets.
2562 use std::borrow::Cow;
2563 use std::sync::Arc;
2564 for versao in ["0.1.0", "1.2.3-alpha.1", "0.0.0", ""] {
2565 let v: CaixaVersion = versao.into();
2566 let via_string: String = String::from(v.clone());
2567 let via_cow: Cow<'static, str> = Cow::from(v.clone());
2568 let via_box: Box<str> = Box::<str>::from(v.clone());
2569 let via_arc: Arc<str> = Arc::<str>::from(v.clone());
2570 let via_as_ref: &str = <CaixaVersion as AsRef<str>>::as_ref(&v);
2571 assert_eq!(via_arc.as_ref(), via_string.as_str());
2572 assert_eq!(via_arc.as_ref(), via_cow.as_ref());
2573 assert_eq!(via_arc.as_ref(), via_box.as_ref());
2574 assert_eq!(via_arc.as_ref(), via_as_ref);
2575 assert_eq!(via_arc.as_ref(), versao);
2576 }
2577 }
2578
2579 #[test]
2580 fn caixa_version_from_borrowed_into_owned_arc_str_routes_through_as_str_accessor() {
2581 // Fail-before-pass-after byte-parity pin on the lifted
2582 // `impl From<&CaixaVersion> for std::sync::Arc<str>` — asserts
2583 // the borrowed-input reverse projection allocates a fresh
2584 // [`std::sync::Arc<str>`] whose bytes byte-equal the
2585 // substrate-primitive [`CaixaVersion::as_str`] accessor on the
2586 // same instance, preserving the source [`CaixaVersion`] intact
2587 // (no move-out). Refuses any future silent detour that would
2588 // route the impl through a divergent projection (a stray
2589 // normalization step, a swap onto the sibling [`fmt::Display`]-
2590 // routed [`ToString::to_string`] surface followed by
2591 // `.into()`, a re-inlining that dereferences `&self.0` outside
2592 // the shared accessor).
2593 use std::sync::Arc;
2594 for versao in ["0.1.0", "1.2.3-alpha.1", "0.0.0", ""] {
2595 let v: CaixaVersion = versao.into();
2596 let via_borrowed: Arc<str> = Arc::<str>::from(&v);
2597 assert_eq!(
2598 via_borrowed.as_ref(),
2599 v.as_str(),
2600 "Arc::<str>::from(&v) must byte-equal CaixaVersion::as_str",
2601 );
2602 // The borrowed-input impl must not move out of the source.
2603 assert_eq!(
2604 v.as_str(),
2605 versao,
2606 "source CaixaVersion must survive borrowed-input projection",
2607 );
2608 }
2609 }
2610
2611 #[test]
2612 fn caixa_version_from_owned_and_borrowed_into_arc_str_agree_on_every_shape() {
2613 // Fail-before-pass-after cross-corner partition pin: the paired
2614 // owned-input [`From<CaixaVersion> for std::sync::Arc<str>`]
2615 // and borrowed-input [`From<&CaixaVersion> for std::sync::Arc<str>`]
2616 // impls resolve to the same bytes on every instance, closing
2617 // the "owned-input move vs. borrowed-input clone" bifurcation
2618 // on the same wrapped body through the [`std::sync::Arc<str>`]
2619 // axis. Refuses any future silent split between the two
2620 // corners (a normalization on one path only, a divergent
2621 // routing that would let `Arc::<str>::from(v.clone())` and
2622 // `Arc::<str>::from(&v)` disagree on the same body).
2623 use std::sync::Arc;
2624 for versao in ["0.1.0", "1.2.3-alpha.1", "0.0.0", ""] {
2625 let v: CaixaVersion = versao.into();
2626 let via_borrowed: Arc<str> = Arc::<str>::from(&v);
2627 let via_owned: Arc<str> = Arc::<str>::from(v.clone());
2628 assert_eq!(via_owned.as_ref(), via_borrowed.as_ref());
2629 assert_eq!(via_borrowed.as_ref(), versao);
2630 }
2631 }
2632
2633 #[test]
2634 fn caixa_version_from_into_owned_rc_str_returns_wrapped_body() {
2635 // Fail-before-pass-after byte-parity pin on the lifted
2636 // `impl From<CaixaVersion> for std::rc::Rc<str>` — asserts the
2637 // owned-input reverse projection routes the wrapper's own
2638 // [`String`] body through [`std::rc::Rc::<str>::from`] verbatim
2639 // (one heap allocation of the single-threaded-refcounted slab, no
2640 // intermediary [`String`] or [`Box<str>`] on the owned-input
2641 // path), so `Rc::<str>::from(v)` returns the same bytes
2642 // `v.as_str()` borrows and round-trips byte-equal through the
2643 // paired forward [`From<String> for CaixaVersion`] constructor
2644 // closing the two-way `Self → Rc<str> → Self` cycle by
2645 // construction. Refuses any future silent detour that would swap
2646 // `Rc::<str>::from(v.0)` for an allocating
2647 // `.as_str().to_owned().into()` cascade (the pre-lift compose
2648 // shape would double-allocate a fresh intermediary [`String`] on
2649 // the way to the same [`Rc<str>`] slot), a stray
2650 // `.trim().to_owned().into()` normalization, or a routing through
2651 // the sibling [`fmt::Display`] emitter that would introduce a
2652 // formatter round-trip.
2653 use std::rc::Rc;
2654 for versao in ["0.1.0", "1.2.3-alpha.1", "0.0.0", ""] {
2655 let v: CaixaVersion = versao.into();
2656 let expected = v.as_str().to_owned();
2657 let rced: Rc<str> = Rc::<str>::from(v.clone());
2658 assert_eq!(
2659 rced.as_ref(),
2660 expected.as_str(),
2661 "Rc::<str>::from(v) must return the wrapper's own bytes verbatim",
2662 );
2663 let round_trip: CaixaVersion = rced.as_ref().to_owned().into();
2664 assert_eq!(
2665 round_trip, v,
2666 "Rc::<str>::from(v) must round-trip byte-equal through \
2667 the From<String> constructor",
2668 );
2669 }
2670 }
2671
2672 #[test]
2673 fn caixa_version_from_into_owned_rc_str_and_arc_str_agree_on_every_shape() {
2674 // Fail-before-pass-after cross-axis partition pin: the owned-
2675 // input [`From<CaixaVersion> for std::rc::Rc<str>`] reverse
2676 // projection and the paired owned-input
2677 // [`From<CaixaVersion> for String`],
2678 // [`From<CaixaVersion> for Cow<'static, str>`],
2679 // [`From<CaixaVersion> for Box<str>`], and
2680 // [`From<CaixaVersion> for std::sync::Arc<str>`] reverse
2681 // projections resolve to the same bytes on every instance, and
2682 // all five agree with the borrowed [`AsRef<str>`] surface on the
2683 // same wrapped body. Refuses any future silent split between the
2684 // five owned-input reverse-projection axes (a stray normalization
2685 // on one path only, a divergent routing that would let
2686 // `Rc::<str>::from(v.clone())`, `Arc::<str>::from(v.clone())`,
2687 // `Box::<str>::from(v.clone())`, `String::from(v.clone())`, and
2688 // `Cow::from(v.clone())` disagree on the same body) that would
2689 // silently split the same-shape owned-move discipline across the
2690 // five reverse-projection targets.
2691 use std::borrow::Cow;
2692 use std::rc::Rc;
2693 use std::sync::Arc;
2694 for versao in ["0.1.0", "1.2.3-alpha.1", "0.0.0", ""] {
2695 let v: CaixaVersion = versao.into();
2696 let owned_string: String = String::from(v.clone());
2697 let owned_cow: Cow<'static, str> = Cow::from(v.clone());
2698 let owned_box: Box<str> = Box::<str>::from(v.clone());
2699 let atomic_handle: Arc<str> = Arc::<str>::from(v.clone());
2700 let single_handle: Rc<str> = Rc::<str>::from(v.clone());
2701 let borrowed_as_ref: &str = <CaixaVersion as AsRef<str>>::as_ref(&v);
2702 assert_eq!(single_handle.as_ref(), owned_string.as_str());
2703 assert_eq!(single_handle.as_ref(), owned_cow.as_ref());
2704 assert_eq!(single_handle.as_ref(), owned_box.as_ref());
2705 assert_eq!(single_handle.as_ref(), atomic_handle.as_ref());
2706 assert_eq!(single_handle.as_ref(), borrowed_as_ref);
2707 assert_eq!(single_handle.as_ref(), versao);
2708 }
2709 }
2710
2711 #[test]
2712 fn caixa_version_from_borrowed_into_owned_rc_str_routes_through_as_str_accessor() {
2713 // Fail-before-pass-after byte-parity pin on the lifted
2714 // `impl From<&CaixaVersion> for std::rc::Rc<str>` — asserts the
2715 // borrowed-input reverse projection allocates a fresh
2716 // [`std::rc::Rc<str>`] whose bytes byte-equal the substrate-
2717 // primitive [`CaixaVersion::as_str`] accessor on the same
2718 // instance, preserving the source [`CaixaVersion`] intact (no
2719 // move-out). Refuses any future silent detour that would route
2720 // the impl through a divergent projection (a stray normalization
2721 // step, a swap onto the sibling [`fmt::Display`]-routed
2722 // [`ToString::to_string`] surface followed by `.into()`, a
2723 // re-inlining that dereferences `&self.0` outside the shared
2724 // accessor).
2725 use std::rc::Rc;
2726 for versao in ["0.1.0", "1.2.3-alpha.1", "0.0.0", ""] {
2727 let v: CaixaVersion = versao.into();
2728 let via_borrowed: Rc<str> = Rc::<str>::from(&v);
2729 assert_eq!(
2730 via_borrowed.as_ref(),
2731 v.as_str(),
2732 "Rc::<str>::from(&v) must byte-equal CaixaVersion::as_str",
2733 );
2734 // The borrowed-input impl must not move out of the source.
2735 assert_eq!(
2736 v.as_str(),
2737 versao,
2738 "source CaixaVersion must survive borrowed-input projection",
2739 );
2740 }
2741 }
2742
2743 #[test]
2744 fn caixa_version_from_owned_and_borrowed_into_rc_str_agree_on_every_shape() {
2745 // Fail-before-pass-after cross-corner partition pin: the paired
2746 // owned-input [`From<CaixaVersion> for std::rc::Rc<str>`] and
2747 // borrowed-input [`From<&CaixaVersion> for std::rc::Rc<str>`]
2748 // impls resolve to the same bytes on every instance, closing the
2749 // "owned-input move vs. borrowed-input clone" bifurcation on the
2750 // same wrapped body through the [`std::rc::Rc<str>`] axis.
2751 // Refuses any future silent split between the two corners (a
2752 // normalization on one path only, a divergent routing that would
2753 // let `Rc::<str>::from(v.clone())` and `Rc::<str>::from(&v)`
2754 // disagree on the same body).
2755 use std::rc::Rc;
2756 for versao in ["0.1.0", "1.2.3-alpha.1", "0.0.0", ""] {
2757 let v: CaixaVersion = versao.into();
2758 let via_borrowed: Rc<str> = Rc::<str>::from(&v);
2759 let via_owned: Rc<str> = Rc::<str>::from(v.clone());
2760 assert_eq!(via_owned.as_ref(), via_borrowed.as_ref());
2761 assert_eq!(via_borrowed.as_ref(), versao);
2762 }
2763 }
2764
2765 #[test]
2766 fn caixa_version_from_str_routes_through_from_str_reference_impl() {
2767 // Fail-before-pass-after byte-parity pin on the lifted
2768 // `impl std::str::FromStr for CaixaVersion` — asserts the
2769 // stdlib parse-set entry point delegates byte-for-byte through
2770 // the paired borrowed-input `impl From<&str> for CaixaVersion`
2771 // constructor above (which wraps `s.to_string()` into the
2772 // newtype's inner `String` slot), so every consumer that reaches
2773 // [`CaixaVersion`] through the standard-library `T: FromStr`-
2774 // bounded parse surface (`str::parse::<CaixaVersion>`, the
2775 // `<CaixaVersion as std::str::FromStr>::from_str` explicit-trait
2776 // spelling on a generic bound, a `clap::value_parser!(CaixaVersion)`
2777 // short-form on a future arg-parse, a `serde_with::DisplayFromStr`
2778 // wrapper on a downstream typed-YAML derive) routes through the
2779 // same wrap the sibling `From<&str>` forward-projection already
2780 // installs. Refuses any future silent detour that would route
2781 // the stdlib entry point through a divergent projection (a stray
2782 // `parse_semver_first` validation gate slipping onto the wrap
2783 // path, a normalization step that would drop whitespace or
2784 // canonicalize a prerelease tag, a swap onto the paired
2785 // [`CaixaVersion::parse`] `Result<semver::Version, VersionError>`
2786 // accessor that would narrow the accept-set to the semver
2787 // grammar's shape ahead of the wrap). Also witnesses the
2788 // `Err = Infallible` type-level shape at compile time under the
2789 // explicit `Result<CaixaVersion, std::convert::Infallible>`
2790 // annotation the loop body binds against — any future accidental
2791 // widening of the error type (a swap onto `type Err =
2792 // VersionError`) trips the annotation at caixa-core build time
2793 // with E0308 (`expected Infallible, found <T>`), strictly stronger
2794 // than a runtime `.unwrap()` on the sibling `.parse()` short-form.
2795 //
2796 // Sweeps the same fixture bodies the sibling
2797 // `caixa_version_as_str_accessor_is_const_fn` /
2798 // `caixa_version_from_owned_and_borrowed_into_rc_str_agree_on_every_shape`
2799 // pins already cover on the paired scalar-accessor and
2800 // owned-vs-borrowed axes: canonical semver, prerelease-shape,
2801 // zero-body, and empty-string corners. Extends the sweep with a
2802 // requirement-shape (`^0.1`), a star (`*`), and a non-semver junk
2803 // body (`not-a-version`) so the total-wrap discipline the
2804 // `Err = Infallible` shape witnesses is asserted across the four
2805 // canonical axes of the input space: semver-shaped bodies the
2806 // paired [`CaixaVersion::parse`] accessor would accept, semver-
2807 // requirement-shaped bodies the sibling [`parse_requirement`]
2808 // surface consumes, empty bodies (which the wrap accepts but
2809 // downstream semver rejects), and non-semver junk (which the
2810 // wrap accepts and downstream semver rejects).
2811 use std::str::FromStr;
2812 for versao in [
2813 "0.1.0",
2814 "1.2.3-alpha.1",
2815 "0.0.0",
2816 "",
2817 "^0.1",
2818 "*",
2819 "not-a-version",
2820 ] {
2821 let via_parse_short_form: Result<CaixaVersion, std::convert::Infallible> =
2822 versao.parse::<CaixaVersion>();
2823 let via_from_str_explicit: Result<CaixaVersion, std::convert::Infallible> =
2824 <CaixaVersion as FromStr>::from_str(versao);
2825 let via_from_ref: CaixaVersion = <CaixaVersion as From<&str>>::from(versao);
2826 let via_parse_ok: CaixaVersion = via_parse_short_form.unwrap();
2827 let via_from_str_ok: CaixaVersion = via_from_str_explicit.unwrap();
2828 assert_eq!(
2829 via_parse_ok.as_str(),
2830 versao,
2831 "str::parse::<CaixaVersion>() must byte-equal the input",
2832 );
2833 assert_eq!(
2834 via_from_str_ok.as_str(),
2835 versao,
2836 "<CaixaVersion as FromStr>::from_str must byte-equal the input",
2837 );
2838 assert_eq!(
2839 via_parse_ok, via_from_ref,
2840 "str::parse::<CaixaVersion>() must byte-equal From<&str>",
2841 );
2842 assert_eq!(
2843 via_from_str_ok, via_from_ref,
2844 "<CaixaVersion as FromStr>::from_str must byte-equal From<&str>",
2845 );
2846 }
2847 }
2848
2849 #[test]
2850 fn caixa_version_from_str_round_trips_through_display_on_every_input() {
2851 // Fail-before-pass-after round-trip pin: the lifted
2852 // `impl std::str::FromStr for CaixaVersion` closes the two-way
2853 // canonical wire-form axis with the paired forward-projection
2854 // [`fmt::Display`] impl at line 29 —
2855 // `s.parse::<CaixaVersion>().unwrap().to_string() == s` for every
2856 // `&str` on the total-wrap axis the newtype installs at rest.
2857 // Refuses any future silent narrowing on either half (a stray
2858 // normalization step slipping onto the [`fmt::Display`] impl that
2859 // would canonicalize the wrapped body ahead of `f.write_str`, a
2860 // divergent wrap on the `FromStr` impl that would swap the paired
2861 // `From<&str>` constructor for a fresh `String::from(s).trim()`-
2862 // style body-mutating projection) so the round-trip theorem the
2863 // pin states remains machine-checked at caixa-core test time.
2864 //
2865 // Peer of the sibling `caixa_version_from_str_routes_through_from_str_reference_impl`
2866 // pin immediately above (which witnesses the byte-parity axis
2867 // against the paired `From<&str>` forward-projection); this pin
2868 // witnesses the same axis against the paired `fmt::Display`
2869 // forward-projection instead, closing the two-way round-trip
2870 // through the standard-library [`fmt::Display`] / [`FromStr`]
2871 // pair the substrate reaches [`CaixaVersion`] through on the
2872 // canonical wire-form axis.
2873 for versao in [
2874 "0.1.0",
2875 "1.2.3-alpha.1",
2876 "0.0.0",
2877 "",
2878 "^0.1",
2879 "*",
2880 "not-a-version",
2881 "1.2.3+build.42",
2882 ] {
2883 let parsed: CaixaVersion = versao.parse::<CaixaVersion>().unwrap();
2884 let displayed: String = parsed.to_string();
2885 assert_eq!(
2886 displayed, versao,
2887 "CaixaVersion::from_str + Display must round-trip byte-for-byte",
2888 );
2889 }
2890 }
2891
2892 #[test]
2893 fn caixa_version_as_ref_bytes_routes_through_as_str_accessor() {
2894 // `<T: AsRef<[u8]>>`-bound-consumer witness helper: a generic
2895 // byte-input function accepts a [`CaixaVersion`] directly through
2896 // the trait bound, without the caller open-coding the two-hop
2897 // `v.as_str().as_bytes()` composition. Lifted to the top of the
2898 // function per `clippy::items_after_statements`.
2899 fn generic_bytes_sink<T: AsRef<[u8]>>(t: T) -> Vec<u8> {
2900 t.as_ref().to_vec()
2901 }
2902 // `blake3::Hasher::update`-shape byte-input surface mock: mirrors
2903 // `blake3::Hasher::update` / `ring::digest::Context::update` /
2904 // `sha2::Sha256::update`'s `impl AsRef<[u8]>`-bound `update`
2905 // signature so a per-`:versao` BLAKE3 content-address closure
2906 // that composes `hasher.update(caixa.versao())` on the
2907 // [`crate::Lacre`] closure builder reaches the substrate-
2908 // primitive [`CaixaVersion::as_str`] accessor through this axis
2909 // and no other.
2910 struct MockHasher(Vec<u8>);
2911 impl MockHasher {
2912 fn new() -> Self {
2913 Self(Vec::new())
2914 }
2915 fn update(&mut self, bytes: impl AsRef<[u8]>) -> &mut Self {
2916 self.0.extend_from_slice(bytes.as_ref());
2917 self
2918 }
2919 fn finalize(self) -> Vec<u8> {
2920 self.0
2921 }
2922 }
2923
2924 // Fail-before-pass-after byte-parity pin on the newly lifted
2925 // `impl AsRef<[u8]> for CaixaVersion` — asserts the trait-
2926 // idiomatic byte-view standard-library impl and the substrate-
2927 // primitive [`CaixaVersion::as_str`] `pub const fn` accessor's
2928 // `.as_bytes()` byte-tail resolve to the same byte-string across
2929 // every canonical `:versao`-shaped input the sibling
2930 // `caixa_version_as_str_accessor_is_const_fn` and
2931 // `caixa_version_from_str_round_trips_through_display_on_every_input`
2932 // pins already sweep (canonical semver, prerelease-shape, zero-
2933 // body, empty-string, requirement-shape, star, non-semver junk,
2934 // build-metadata-tail). Opens the trait-idiomatic byte-view axis
2935 // on the substrate's core String-wrapper newtype primitive
2936 // [`CaixaVersion`], mirroring the paired [`AsRef<[u8]>`] axis
2937 // every closed-set fieldless typed enum peer already carries.
2938 for versao in [
2939 "0.1.0",
2940 "1.2.3-alpha.1",
2941 "0.0.0",
2942 "",
2943 "^0.1",
2944 "*",
2945 "not-a-version",
2946 "1.2.3+build.42",
2947 ] {
2948 let v: CaixaVersion = versao.into();
2949 let via_trait: &[u8] = <CaixaVersion as AsRef<[u8]>>::as_ref(&v);
2950 let via_method_bytes: &[u8] = v.as_str().as_bytes();
2951 assert_eq!(
2952 via_trait, via_method_bytes,
2953 "AsRef<[u8]> for CaixaVersion impl must byte-equal \
2954 CaixaVersion::as_str().as_bytes() on {versao:?} — \
2955 divergence signals a silent detour off the substrate-\
2956 primitive accessor",
2957 );
2958 // Cross-axis witness against the paired str-view axes'
2959 // `.as_bytes()` byte-tails: the newly lifted byte-view
2960 // impl and every str-view axis on the same primitive
2961 // ([`AsRef<str>`], [`fmt::Display`], [`CaixaVersion::as_str`])
2962 // must resolve to the same byte-tail by construction — any
2963 // future silent split at the substrate-primitive accessor
2964 // trips here rather than at a downstream consumer.
2965 let str_view_ref: &str = <CaixaVersion as AsRef<str>>::as_ref(&v);
2966 assert_eq!(
2967 via_trait,
2968 str_view_ref.as_bytes(),
2969 "AsRef<[u8]> and AsRef<str> for CaixaVersion must resolve \
2970 to byte-equal byte-tails on {versao:?}",
2971 );
2972 let display_bytes = v.to_string();
2973 assert_eq!(
2974 via_trait,
2975 display_bytes.as_bytes(),
2976 "AsRef<[u8]> and <CaixaVersion as fmt::Display>::to_string \
2977 must resolve to byte-equal byte-tails on {versao:?}",
2978 );
2979 let borrow_view: &str = <CaixaVersion as std::borrow::Borrow<str>>::borrow(&v);
2980 assert_eq!(
2981 via_trait,
2982 borrow_view.as_bytes(),
2983 "AsRef<[u8]> and Borrow<str> for CaixaVersion must resolve \
2984 to byte-equal byte-tails on {versao:?}",
2985 );
2986 // `<T: AsRef<[u8]>>`-bound-consumer witness: a generic
2987 // byte-input function accepts the wrapper directly and
2988 // returns the same bytes the substrate-primitive accessor's
2989 // `.as_bytes()` byte-tail carries.
2990 let sunk_owned: Vec<u8> = generic_bytes_sink(v.clone());
2991 assert_eq!(sunk_owned, via_method_bytes);
2992 let sunk_borrowed: Vec<u8> = generic_bytes_sink(&v);
2993 assert_eq!(sunk_borrowed, via_method_bytes);
2994 // `blake3::Hasher::update`-shape witness: the
2995 // per-`:versao` BLAKE3 content-address closure builder reaches
2996 // the substrate-primitive accessor through the byte-view axis
2997 // and folds the same bytes the paired str-view axes surface.
2998 let mut mock_hasher = MockHasher::new();
2999 mock_hasher.update(&v);
3000 let folded_bytes = mock_hasher.finalize();
3001 assert_eq!(folded_bytes, via_method_bytes);
3002 }
3003 }
3004
3005 #[test]
3006 fn caixa_version_from_into_owned_vec_bytes_returns_wrapped_body() {
3007 // Fail-before-pass-after byte-parity pin on the lifted
3008 // `impl From<CaixaVersion> for Vec<u8>` — asserts the owned-input
3009 // byte-owned forward-projection routes the wrapper's own heap
3010 // allocation through [`String::into_bytes`] verbatim (no re-copy
3011 // of the wrapped body's bytes, no normalization detour) so
3012 // `Vec::<u8>::from(v)` returns the same bytes `v.as_str()`
3013 // borrows via `.as_bytes()`. Refuses any future silent detour
3014 // that would swap the move on `v.0.into_bytes()` for an
3015 // allocating `.as_str().as_bytes().to_vec()` cascade (the
3016 // pre-lift compose shape), a `String::from(v).into_bytes()`
3017 // two-hop reverse-then-move shape, a stray
3018 // `.trim().as_bytes().to_vec()` normalization, or a routing
3019 // through the sibling [`fmt::Display`] emitter that would
3020 // introduce a formatter round-trip. Closes the byte-owned
3021 // forward-projection axis in lockstep with the paired str-owned
3022 // [`From<CaixaVersion> for String`] axis (which routes through
3023 // `v.0`).
3024 for versao in [
3025 "0.1.0",
3026 "1.2.3-alpha.1",
3027 "0.0.0",
3028 "",
3029 "^0.1",
3030 "*",
3031 "not-a-version",
3032 "1.2.3+build.42",
3033 ] {
3034 let v: CaixaVersion = versao.into();
3035 let expected: Vec<u8> = v.as_str().as_bytes().to_vec();
3036 let owned: Vec<u8> = Vec::<u8>::from(v);
3037 assert_eq!(
3038 owned, expected,
3039 "Vec::<u8>::from(v) must return the wrapper's own bytes verbatim on {versao:?}",
3040 );
3041 assert_eq!(
3042 owned,
3043 versao.as_bytes(),
3044 "Vec::<u8>::from(v) must byte-equal the pre-lift wrapped \
3045 String storage on round-trip through the From<&str> constructor",
3046 );
3047 // Round-trip witness through the paired forward constructor:
3048 // the emitted owned byte-tail rematerializes into a
3049 // [`String`] via [`String::from_utf8`] and folds through
3050 // the paired [`From<String> for CaixaVersion`] constructor
3051 // to the same [`CaixaVersion`] value — closes the
3052 // `Self → Vec<u8> → String → Self` round-trip whenever the
3053 // wrapped body is valid UTF-8, which every `SemVer`-shaped
3054 // `:versao` body is by construction (semver's grammar is
3055 // ASCII-only).
3056 if let Ok(round) = String::from_utf8(owned) {
3057 let back: CaixaVersion = round.into();
3058 assert_eq!(back.as_str(), versao);
3059 }
3060 }
3061 }
3062
3063 #[test]
3064 fn caixa_version_from_borrowed_into_owned_vec_bytes_routes_through_as_str_accessor() {
3065 // Fail-before-pass-after byte-parity pin on the lifted
3066 // `impl From<&CaixaVersion> for Vec<u8>` — asserts the
3067 // borrowed-input byte-owned forward-projection allocates a fresh
3068 // [`Vec<u8>`] whose bytes byte-equal the substrate-primitive
3069 // [`CaixaVersion::as_str`] accessor's `.as_bytes()` byte-tail
3070 // (via [`slice::to_vec`]) so `Vec::<u8>::from(&v)` returns the
3071 // same bytes without consuming the source wrapper. Refuses any
3072 // future silent detour: a stray normalization step that would
3073 // drop whitespace or canonicalize a prerelease tag ahead of the
3074 // byte-owned emit, a swap onto `String::from(v.clone()).into_bytes()`
3075 // that would spuriously clone the intermediate [`String`], or a
3076 // routing through the sibling [`fmt::Display`] emitter that
3077 // would introduce a formatter round-trip. Includes a source-
3078 // survival witness — the borrowed input remains readable after
3079 // the projection returns, confirming the impl takes only a
3080 // borrow and does not silently move out of the source.
3081 for versao in [
3082 "0.1.0",
3083 "1.2.3-alpha.1",
3084 "0.0.0",
3085 "",
3086 "^0.1",
3087 "*",
3088 "not-a-version",
3089 "1.2.3+build.42",
3090 ] {
3091 let v: CaixaVersion = versao.into();
3092 let via_borrowed: Vec<u8> = Vec::<u8>::from(&v);
3093 assert_eq!(
3094 via_borrowed,
3095 v.as_str().as_bytes(),
3096 "Vec::<u8>::from(&v) must byte-equal CaixaVersion::as_str().as_bytes() \
3097 on {versao:?} — divergence signals a silent detour off \
3098 the substrate-primitive accessor",
3099 );
3100 // Source-survival witness: `v` is borrowed, not moved, so
3101 // the pre-existing borrow-projection axes stay reachable
3102 // through the same instance after the byte-owned projection
3103 // returns.
3104 assert_eq!(v.as_str(), versao);
3105 }
3106 }
3107
3108 #[test]
3109 fn caixa_version_from_owned_and_borrowed_into_vec_bytes_agree_on_every_shape() {
3110 // Fail-before-pass-after cross-axis partition pin: the paired
3111 // owned-input [`From<CaixaVersion> for Vec<u8>`] and
3112 // borrowed-input [`From<&CaixaVersion> for Vec<u8>`] impls
3113 // resolve to the same byte-tail on every instance, and both
3114 // agree byte-for-byte with the pre-existing byte-view
3115 // [`AsRef<[u8]>`] axis on the same primitive. Closes the
3116 // "owned-input move vs. borrowed-input clone" bifurcation on
3117 // the [`Vec<u8>`] axis and the "owned-heap vs. borrowed-view"
3118 // bifurcation between the byte-owned forward-projection and the
3119 // pre-existing borrow-projection byte-view axis. Refuses any
3120 // future silent split between the two corners (a normalization
3121 // on one path only, a divergent routing that would let
3122 // `Vec::<u8>::from(v.clone())` and `Vec::<u8>::from(&v)`
3123 // disagree, or a swap on `AsRef::<[u8]>::as_ref` that would
3124 // diverge from either projection).
3125 for versao in [
3126 "0.1.0",
3127 "1.2.3-alpha.1",
3128 "0.0.0",
3129 "",
3130 "^0.1",
3131 "*",
3132 "not-a-version",
3133 "1.2.3+build.42",
3134 ] {
3135 let v: CaixaVersion = versao.into();
3136 let via_owned: Vec<u8> = Vec::<u8>::from(v.clone());
3137 let via_borrowed: Vec<u8> = Vec::<u8>::from(&v);
3138 let via_as_ref: &[u8] = <CaixaVersion as AsRef<[u8]>>::as_ref(&v);
3139 assert_eq!(via_owned, via_borrowed);
3140 assert_eq!(via_borrowed.as_slice(), via_as_ref);
3141 assert_eq!(via_borrowed, versao.as_bytes());
3142 }
3143 }
3144
3145 #[test]
3146 fn caixa_version_from_into_owned_cow_bytes_returns_owned_wrapped_body() {
3147 // Fail-before-pass-after byte-parity + [`Cow::Owned`]-arm pin
3148 // on the lifted `impl From<CaixaVersion> for
3149 // std::borrow::Cow<'static, [u8]>` — asserts the owned-input
3150 // byte-owned reverse projection routes the wrapper's own heap
3151 // allocation through `Cow::Owned(v.0.into_bytes())` verbatim
3152 // (no re-copy, no normalization detour, no `Cow::Borrowed`
3153 // misclassification that would demand a `&'static [u8]` the
3154 // runtime wrapper cannot carry), so the emitted [`Cow`] byte-
3155 // equals the substrate-primitive [`CaixaVersion::as_str`]
3156 // accessor's `.as_bytes()` byte-tail on the same instance and
3157 // round-trips byte-equal through the paired forward
3158 // [`From<String> for CaixaVersion`] constructor after
3159 // re-materializing through [`String::from_utf8`]. Refuses any
3160 // future silent detour: a swap of the move on `v.0.into_bytes()`
3161 // for an allocating `.as_str().as_bytes().to_vec()` cascade
3162 // (the pre-lift compose shape would double-allocate a fresh
3163 // intermediary [`Vec<u8>`] on the way to the same
3164 // [`Cow::Owned`] arm), a stray `.trim().as_bytes().to_vec()`
3165 // normalization, or a mis-routing through [`Cow::Borrowed`] on
3166 // a non-`'static` byte-string that would not type-check.
3167 use std::borrow::Cow;
3168 for versao in [
3169 "0.1.0",
3170 "1.2.3-alpha.1",
3171 "0.0.0",
3172 "",
3173 "^0.1",
3174 "*",
3175 "not-a-version",
3176 "1.2.3+build.42",
3177 ] {
3178 let v: CaixaVersion = versao.into();
3179 let expected: Vec<u8> = v.as_str().as_bytes().to_vec();
3180 let cow: Cow<'static, [u8]> = Cow::from(v.clone());
3181 assert!(
3182 matches!(cow, Cow::Owned(_)),
3183 "From<CaixaVersion> for Cow<'static, [u8]> must land on \
3184 the Cow::Owned arm — a runtime String wrapper cannot \
3185 promise the 'static lifetime the Cow::Borrowed arm \
3186 requires on {versao:?}",
3187 );
3188 assert_eq!(
3189 cow.as_ref(),
3190 expected.as_slice(),
3191 "Cow::from(v) must return the wrapper's own bytes verbatim on {versao:?}",
3192 );
3193 assert_eq!(
3194 cow.as_ref(),
3195 versao.as_bytes(),
3196 "Cow::from(v) must byte-equal the pre-lift wrapped String \
3197 storage on round-trip through the From<&str> constructor",
3198 );
3199 // Round-trip witness through the paired forward constructor:
3200 // the emitted owned byte-tail rematerializes into a
3201 // [`String`] via [`String::from_utf8`] and folds through
3202 // the paired [`From<String> for CaixaVersion`] constructor
3203 // to the same [`CaixaVersion`] value — closes the
3204 // `Self → Cow<'static, [u8]> → Vec<u8> → String → Self`
3205 // round-trip whenever the wrapped body is valid UTF-8, which
3206 // every `SemVer`-shaped `:versao` body is by construction
3207 // (semver's grammar is ASCII-only).
3208 if let Ok(round) = String::from_utf8(cow.into_owned()) {
3209 let back: CaixaVersion = round.into();
3210 assert_eq!(back.as_str(), versao);
3211 }
3212 }
3213 }
3214
3215 #[test]
3216 fn caixa_version_from_into_owned_cow_bytes_and_vec_bytes_agree_on_every_shape() {
3217 // Fail-before-pass-after cross-axis partition pin: the owned-
3218 // input [`From<CaixaVersion> for Cow<'static, [u8]>`] byte-owned
3219 // reverse projection and the paired owned-input
3220 // [`From<CaixaVersion> for Vec<u8>`] byte-owned reverse
3221 // projection resolve to the same bytes on every instance, and
3222 // both agree with the pre-existing borrowed [`AsRef<[u8]>`]
3223 // byte-view axis on the same wrapped body. Refuses any future
3224 // silent split between the two owned-input byte-owned reverse-
3225 // projection axes (a stray normalization on one path only, a
3226 // divergent routing that would let `Cow::from(v.clone())` and
3227 // `Vec::<u8>::from(v.clone())` disagree on the same body) that
3228 // would silently split the same-shape owned-move discipline
3229 // across the two byte-family reverse-projection targets.
3230 use std::borrow::Cow;
3231 for versao in [
3232 "0.1.0",
3233 "1.2.3-alpha.1",
3234 "0.0.0",
3235 "",
3236 "^0.1",
3237 "*",
3238 "not-a-version",
3239 "1.2.3+build.42",
3240 ] {
3241 let v: CaixaVersion = versao.into();
3242 let via_vec: Vec<u8> = Vec::<u8>::from(v.clone());
3243 let via_cow: Cow<'static, [u8]> = Cow::from(v.clone());
3244 let via_as_ref: &[u8] = <CaixaVersion as AsRef<[u8]>>::as_ref(&v);
3245 assert_eq!(via_cow.as_ref(), via_vec.as_slice());
3246 assert_eq!(via_cow.as_ref(), via_as_ref);
3247 assert_eq!(via_cow.as_ref(), versao.as_bytes());
3248 }
3249 }
3250
3251 #[test]
3252 fn caixa_version_from_borrowed_into_owned_cow_bytes_routes_through_as_str_accessor() {
3253 // Fail-before-pass-after byte-parity + [`Cow::Owned`]-arm pin
3254 // on the lifted `impl From<&CaixaVersion> for
3255 // std::borrow::Cow<'static, [u8]>` — asserts the borrowed-input
3256 // byte-owned reverse projection allocates a fresh
3257 // [`Cow::Owned`] whose bytes byte-equal the substrate-primitive
3258 // [`CaixaVersion::as_str`] accessor's `.as_bytes()` byte-tail
3259 // on the same instance (via [`slice::to_vec`]), preserving the
3260 // source [`CaixaVersion`] intact (no move-out). Refuses any
3261 // future silent detour that would route the impl through a
3262 // divergent projection (a stray normalization step that would
3263 // drop whitespace or canonicalize a prerelease tag ahead of the
3264 // byte-owned emit, a mis-routing onto [`Cow::Borrowed`] on a
3265 // non-`'static` byte-string that would not type-check, a
3266 // re-inlining that dereferences `&self.0` outside the shared
3267 // accessor).
3268 use std::borrow::Cow;
3269 for versao in [
3270 "0.1.0",
3271 "1.2.3-alpha.1",
3272 "0.0.0",
3273 "",
3274 "^0.1",
3275 "*",
3276 "not-a-version",
3277 "1.2.3+build.42",
3278 ] {
3279 let v: CaixaVersion = versao.into();
3280 let via_borrowed: Cow<'static, [u8]> = Cow::from(&v);
3281 assert!(
3282 matches!(via_borrowed, Cow::Owned(_)),
3283 "From<&CaixaVersion> for Cow<'static, [u8]> must land on \
3284 the Cow::Owned arm — a runtime String wrapper cannot \
3285 promise the 'static lifetime the Cow::Borrowed arm \
3286 requires on {versao:?}",
3287 );
3288 assert_eq!(
3289 via_borrowed.as_ref(),
3290 v.as_str().as_bytes(),
3291 "Cow::from(&v) must byte-equal CaixaVersion::as_str().as_bytes() \
3292 on {versao:?} — divergence signals a silent detour off \
3293 the substrate-primitive accessor",
3294 );
3295 // The borrowed-input impl must not move out of the source.
3296 assert_eq!(
3297 v.as_str(),
3298 versao,
3299 "source CaixaVersion must survive borrowed-input projection",
3300 );
3301 }
3302 }
3303
3304 #[test]
3305 fn caixa_version_from_owned_and_borrowed_into_cow_bytes_agree_on_every_shape() {
3306 // Fail-before-pass-after cross-axis partition pin: the paired
3307 // owned-input [`From<CaixaVersion> for Cow<'static, [u8]>`] and
3308 // borrowed-input [`From<&CaixaVersion> for Cow<'static, [u8]>`]
3309 // impls resolve to the same bytes on every instance, closing
3310 // the "owned-input move vs. borrowed-input clone" bifurcation
3311 // on the same wrapped body through the [`Cow<'static, [u8]>`]
3312 // axis. Refuses any future silent split between the two corners
3313 // (a normalization on one path only, a divergent routing that
3314 // would let `Cow::from(v.clone())` and `Cow::from(&v)` disagree
3315 // on the same body). Both corners must land on [`Cow::Owned`]
3316 // — the runtime wrapper's storage rules out the borrowed arm
3317 // on both input shapes alike.
3318 use std::borrow::Cow;
3319 for versao in [
3320 "0.1.0",
3321 "1.2.3-alpha.1",
3322 "0.0.0",
3323 "",
3324 "^0.1",
3325 "*",
3326 "not-a-version",
3327 "1.2.3+build.42",
3328 ] {
3329 let v: CaixaVersion = versao.into();
3330 let via_borrowed: Cow<'static, [u8]> = Cow::from(&v);
3331 let via_owned: Cow<'static, [u8]> = Cow::from(v.clone());
3332 let via_as_ref: &[u8] = <CaixaVersion as AsRef<[u8]>>::as_ref(&v);
3333 assert!(matches!(via_borrowed, Cow::Owned(_)));
3334 assert!(matches!(via_owned, Cow::Owned(_)));
3335 assert_eq!(via_owned.as_ref(), via_borrowed.as_ref());
3336 assert_eq!(via_borrowed.as_ref(), via_as_ref);
3337 assert_eq!(via_borrowed.as_ref(), versao.as_bytes());
3338 }
3339 }
3340}