pub struct TypeRef {
pub name: String,
pub inner: Option<Box<TypeRef>>,
pub choices: Option<Vec<String>>,
pub variants: Option<Vec<TypeRef>>,
}Fields§
§name: String§inner: Option<Box<TypeRef>>§choices: Option<Vec<String>>Populated only for string-literal union types; in that case name is
the sentinel "choice" and choices holds the variant strings in
declaration order. None for every other type. Variant validation
(non-empty, unique, ≥2) is the analyzer’s job, not the parser’s.
variants: Option<Vec<TypeRef>>Populated only for discriminated-union types (general A | B | ...
including the binary T | Unable special case). When Some, name
is the sentinel "variant_union" (mirroring "choice"), both
inner and choices are None, and variants holds every arm in
source order with length in [2, MAX_UNION_ARMS]. The analyzer
enforces arm-record-only, ≤8, no duplicates, and
return-position-only usage in v1.
Implementations§
Source§impl TypeRef
impl TypeRef
Sourcepub fn primitive(name: impl Into<String>) -> Self
pub fn primitive(name: impl Into<String>) -> Self
Build a primitive or named type reference (no generic inner, no
choice variants). Use this in preference to a struct literal so the
choices field stays consistently None at non-choice sites.
Sourcepub fn optional(inner: TypeRef) -> Self
pub fn optional(inner: TypeRef) -> Self
Build an optional type T? wrapping inner (D2). Idempotent:
applying this to a type that is already optional returns the same
shape (no double-wrap), matching most languages’ T?? collapse.
Sourcepub fn is_optional(&self) -> bool
pub fn is_optional(&self) -> bool
true iff this TypeRef is an Optional[T] sentinel.
Sourcepub fn optional_inner(&self) -> Option<&TypeRef>
pub fn optional_inner(&self) -> Option<&TypeRef>
Borrow the wrapped T from an Optional[T]; None for non-optional.
Sourcepub fn variant_union(arms: Vec<TypeRef>) -> Self
pub fn variant_union(arms: Vec<TypeRef>) -> Self
Build a discriminated union from an ordered arm list. Grammar
guarantees arms.len() >= 2; arm-count caps are analyzer-enforced
(AKRIBES-E-UNION-009) so oversized unions reach the analyzer as
parsed ASTs instead of panicking in the parser. The binary
T | Unable case is just variant_union(vec![T, Unable]).
Sourcepub fn union_with_unable(success: TypeRef) -> Self
pub fn union_with_unable(success: TypeRef) -> Self
Build a binary union success | Unable. Kept as a named constructor
because every #157 call site uses it; internally delegates to
[variant_union] with [success, Unable] in canonical source
order.
Sourcepub fn is_variant_union(&self) -> bool
pub fn is_variant_union(&self) -> bool
Return true iff this TypeRef is a discriminated-union sentinel
(any arm count).
Sourcepub fn union_arms(&self) -> Option<&[TypeRef]>
pub fn union_arms(&self) -> Option<&[TypeRef]>
Slice over the declared arms in source order (or None for
non-union types).
Sourcepub fn is_union_with_unable(&self) -> bool
pub fn is_union_with_unable(&self) -> bool
Return true iff this TypeRef is a binary union whose two arms
are exactly one non-Unable record and one Unable. Used by every
#157 call site that gates on “this is a T | Unable return type” —
kept for backwards compatibility and cheap pattern-matching.
Sourcepub fn unwrap_union_success(&self) -> Option<&TypeRef>
pub fn unwrap_union_success(&self) -> Option<&TypeRef>
Return the non-Unable branch of a binary T | Unable, or None if
this is not exactly such a union. N-ary unions and unions without
an Unable arm return None — callers that need the general arm
list should use [union_arms].
Sourcepub fn union_success_arm(&self) -> Option<&TypeRef>
pub fn union_success_arm(&self) -> Option<&TypeRef>
Return the declared success arm of any discriminated union — the
first arm in source order. Used for retry gating and
on <variant> default type-checking. Returns None for non-union
types.