pub enum KwargPath {
Named(String),
Item {
key: String,
idx: usize,
},
Slot(usize),
}Expand description
Closed-set identifier for a kwargs-path projection — the form: label
shape that a typed-entry kwarg failure renders into the compile error in {form}: prefix of a LispError::TypeMismatch diagnostic. Encodes
the three reachable path shapes the kwargs gate emits — :<key> for a
named kwarg (extract_string / extract_int / etc. failure),
:<key>[<idx>] for the Nth item of a list-typed kwarg
(extract_string_list per-item failure), and kwargs[<idx>] for an
even-position slot that failed the “this-position-must-be-a-keyword”
gate before a key was known (parse_kwargs direct call) — as a typed
borrowed enum, so authoring tools (REPL, LSP, tatara-check) bind to
path-shape identity (KwargPath::Item { .. } etc.) rather than
substring-matching the rendered prefix.
Mirror at the kwargs-path-shape boundary of the prior-run
MacroDefHead (macro-definition-head closed set),
CompilerSpecIoStage (disk-persistence surface),
TemplateInvariantKind (bytecode-runtime surface), and UnquoteForm
(template-marker syntactic forms) closed-set lifts: those enums key
their respective rejection variants on a typed identity carried inside
the variant’s data shape; this enum keys the THREE distinct form:
label shapes emitted by the kwarg-gate’s typed-entry chain on a typed
path identity. The three format! literals that used to live inline
in domain.rs::kwarg_form / kwarg_item_form / kwargs_pos_form
(three byte-identical format! shapes, one per helper) collapse into
ONE Display impl on this enum — the canonical literals (":<key>"
/ ":<key>[<idx>]" / "kwargs[<idx>]") live in ONE place, so a typo
in any one of the three shapes can never drift independent of the
others (THEORY.md §VI.1 three-times rule). Adding a fourth path shape
(e.g., :<key>.<field> for nested-struct kwarg failures or
:<key>::<variant> for sum-typed kwarg failures) requires extending
this enum, which rustc-enforces matching at the Display projection
site.
KwargPath owns its key payload as String so it can inhabit
LispError::TypeMismatch.form (and any future error variant) without
a borrow constraint. The owned shape is the typed-slot promotion the
prior-run KwargPath landing pre-staged: every projection site that
used to produce a String via KwargPath::Named(key).to_string() (the
three sibling helpers kwarg_form / kwarg_item_form /
kwargs_pos_form and the fourth kwarg_deserialize_form helper) now
produces a typed KwargPath value directly; type_mismatch and every
TypeMismatch.form consumer pattern-match on the variant identity
(KwargPath::Item { key, idx }, KwargPath::Slot(idx), etc.) instead
of substring-parsing the rendered prefix.
Copy is dropped because String is not Copy; Clone + Debug + PartialEq + Eq are retained (same posture as every other owned-data
LispError field). The closed-set structural-completeness floor is
unchanged — only the data ownership changed.
Theory anchor: THEORY.md §V.1 — knowable platform; the closed set of
kwargs-path shapes becomes a TYPE rather than three byte-identical
format! literals scattered across helper definitions. THEORY.md
§VI.1 — generation over composition; the typed enum lands the
structural-completeness floor for the kwargs-path surface, parallel
to how CompilerSpecIoStage lands it for the disk-persistence
surface, MacroDefHead for the macro-definition-head surface,
TemplateInvariantKind for the bytecode-runtime surface, and
UnquoteForm for the template-marker surface. THEORY.md §II.1
invariant 1 — typed entry; the kwargs-path’s renderable identity is
part of the proof of WHICH kwarg-gate fired, and the typed enum makes
that identity first-class — now as load-bearing data on the
TypeMismatch variant rather than as a projection-to-String.
Variants§
Named(String)
:<key> — failure at a named kwarg (extract_string,
extract_int, extract_float, extract_bool, etc.). The key
is the offending kwarg’s identifier, owned so the variant lives
independent of the call frame.
Item
:<key>[<idx>] — failure at the Nth item of a list-typed kwarg
(extract_string_list per-item failure). The key is the
containing kwarg’s identifier (owned); idx is the 0-based item
index inside that kwarg’s list value.
Slot(usize)
kwargs[<idx>] — failure at the Nth slot of the kwargs slice
before a key was known (parse_kwargs’s
“this-position-must-be-a-keyword” gate firing on an even-position
slot). idx is the 0-based position into the raw kwargs slice
(not into a particular kwarg’s value).
Implementations§
Source§impl KwargPath
impl KwargPath
Sourcepub fn named(key: &str) -> Self
pub fn named(key: &str) -> Self
Owned constructor for the :<key> shape — used by every call site
that has a &str borrow of the kwarg identifier and wants to lift
it into the typed enum without an inline .to_string() projection.
Sourcepub fn item(key: &str, idx: usize) -> Self
pub fn item(key: &str, idx: usize) -> Self
Owned constructor for the :<key>[<idx>] shape — sibling of
named, threading the per-item index alongside the kwarg key.
Sourcepub const fn kind(&self) -> KwargPathKind
pub const fn kind(&self) -> KwargPathKind
Discriminator projection — strips the payload and returns the
closed-set KwargPathKind. The same shape every sibling
payload-carrying closed-set enum in the workspace projects through
(e.g. tatara_process::lifetime_clock::AutoTerminate::kind →
crate::error::KwargPath’s tatara-process cousin
AutoTerminateKind, TerminateReason::kind →
TerminateReasonKind, crate::matrix::SelectStrategy::kind →
SelectStrategyKind).
Consumers that group LispError::TypeMismatch /
LispError::KwargDeserialize failures by path-shape
CATEGORY rather than full path identity (failure-cluster metrics
labelled path_kind=named / path_kind=item / path_kind=slot,
an LSP that surfaces “this is a per-item failure” before drilling
into the bracket-suffix, a future tatara-check diagnostic
histogram that buckets by kind) project through this method
instead of destructuring the variant and discarding the payload at
every site. Adding a fourth path shape (e.g., :<key>.<field>
for nested-struct kwarg failures or :<key>::<variant> for
sum-typed kwarg failures) requires extending KwargPathKind,
which rustc-enforces matching at this projection.