pub fn require_kind(
caixa: &Caixa,
expected: CaixaKind,
) -> Result<(), KindMismatch>Expand description
Predicate: assert that caixa.kind == expected, returning a typed
KindMismatch view (carrying Caixa::nome) on rejection. The
canonical entry-point every per-kind renderer wraps in its own
thiserror Error variant via #[from] — the call site
becomes a single caixa_core::require_kind(caixa, CaixaKind::X)?;
in place of the prior inline if caixa.kind != CaixaKind::X { return Err(Error::NotAnX(caixa.kind)); } block.
Lifted to a single helper so a future per-kind renderer
(caixa-otel, the future per-Aplicacao CR materializer the M3.x
roadmap acknowledges, the future per-Supervisor reconciler
renderer) gets the same naming-the-offending-caixa diagnostic for
free, and a future change to the diagnostic format (e.g. adding
a Caixa::versao suffix once multi-version-skew authoring lands)
is one edit here, not a coordinated rewrite of every renderer.
§Errors
Returns KindMismatch when caixa.kind != expected. The error
carries the caixa’s :nome so the diagnostic names the offending
caixa.lisp — same shape every renderer’s Error::From<KindMismatch>
converts into the renderer’s local error type.