pub struct LemmaType {
pub name: Option<String>,
pub specifications: TypeSpecification,
pub extends: TypeExtends,
pub measure_binding_unit: Option<String>,
}Expand description
Resolved type after planning
Contains a type specification and optional name. Created during planning from TypeSpecification in the AST.
Fields§
§name: Option<String>Optional type name (e.g., “age”, “temperature”)
specifications: TypeSpecificationThe type specification (Boolean, Number, Measure, etc.).
extends: TypeExtendsWhat this type extends (primitive or custom from a spec)
measure_binding_unit: Option<String>Bound display/arithmetic unit for measure values (from literal bind or
signature-index hit). When set, LemmaType::measure_runtime_signature
returns [(this, 1)] instead of the type’s canonical unit.
Implementations§
Source§impl LemmaType
impl LemmaType
Sourcepub fn map_measure<F>(self, f: F) -> Self
pub fn map_measure<F>(self, f: F) -> Self
Functional update of the Measure payload (units + decomposition).
Non-Measure variants pass through unchanged. The transform receives the owned
units and decomposition and returns the replacements.
Sourcepub fn new(
name: String,
specifications: TypeSpecification,
extends: TypeExtends,
) -> Self
pub fn new( name: String, specifications: TypeSpecification, extends: TypeExtends, ) -> Self
Create a new type with a name
Sourcepub fn without_name(
specifications: TypeSpecification,
extends: TypeExtends,
) -> Self
pub fn without_name( specifications: TypeSpecification, extends: TypeExtends, ) -> Self
Create a type without a name (anonymous/inline type)
Sourcepub fn primitive(specifications: TypeSpecification) -> Self
pub fn primitive(specifications: TypeSpecification) -> Self
Create a primitive type (no name, extends Primitive)
Sourcepub fn with_measure_binding_unit(self, unit_name: impl Into<String>) -> Self
pub fn with_measure_binding_unit(self, unit_name: impl Into<String>) -> Self
Prefer unit_name for [measure_runtime_signature] (bind / signature-index hit).
Sourcepub fn is_boolean(&self) -> bool
pub fn is_boolean(&self) -> bool
Check if this type is boolean
pub fn matches_primitive_kind(&self, kind: PrimitiveKind) -> bool
Sourcepub fn is_measure(&self) -> bool
pub fn is_measure(&self) -> bool
Check if this type is measure
pub fn is_measure_range(&self) -> bool
pub fn is_number_range(&self) -> bool
Sourcepub fn is_numeric(&self) -> bool
pub fn is_numeric(&self) -> bool
Check if this type is numeric (either measure or number)
pub fn is_date_range(&self) -> bool
pub fn is_time_range(&self) -> bool
pub fn has_trait_duration(&self) -> bool
pub fn is_duration_like_measure(&self) -> bool
pub fn is_duration_like(&self) -> bool
pub fn has_trait_calendar(&self) -> bool
pub fn is_calendar_like_measure(&self) -> bool
pub fn is_calendar_like(&self) -> bool
pub fn is_ratio_range(&self) -> bool
pub fn is_calendar_measure_range(&self) -> bool
pub fn is_calendar_like_range(&self) -> bool
pub fn is_range(&self) -> bool
Sourcepub fn is_undetermined(&self) -> bool
pub fn is_undetermined(&self) -> bool
True if this type is the undetermined sentinel (type could not be inferred).
Sourcepub fn has_same_base_type(&self, other: &LemmaType) -> bool
pub fn has_same_base_type(&self, other: &LemmaType) -> bool
Check if two types have the same base type specification (ignoring constraints)
Sourcepub fn measure_family_name(&self) -> Option<&str>
pub fn measure_family_name(&self) -> Option<&str>
For measure types, returns the family name (root of the extension chain). For Custom extends, returns the family field; for Primitive, returns the type’s own name (the type is the root). For non-measure types, returns None.
Sourcepub fn ratio_family_name(&self) -> Option<&str>
pub fn ratio_family_name(&self) -> Option<&str>
For ratio types, returns the family name (root of the extension chain).
Sourcepub fn same_measure_family(&self, other: &LemmaType) -> bool
pub fn same_measure_family(&self, other: &LemmaType) -> bool
Returns true if both types are measure and belong to the same named measure family.
pub fn compatible_with_anonymous_measure(&self, other: &LemmaType) -> bool
Sourcepub fn undetermined_type() -> Self
pub fn undetermined_type() -> Self
LemmaType sentinel for undetermined type (used during inference when a type cannot be determined). Propagates through expressions and is never present in a validated graph.
Sourcepub fn decimal_places(&self) -> Option<u8>
pub fn decimal_places(&self) -> Option<u8>
Decimal places for display (Number, Measure, and Ratio). Used by formatters. Ratio: optional, no default; when None display is normalized (no trailing zeros).
Sourcepub fn try_rational_as_decimal_string(
&self,
magnitude: &RationalInteger,
) -> Result<String, NumericFailure>
pub fn try_rational_as_decimal_string( &self, magnitude: &RationalInteger, ) -> Result<String, NumericFailure>
Convert a rational magnitude to a decimal string for API output.
Applies this type’s decimal_places when set. Returns [NumericFailure::Overflow]
when |magnitude| > Decimal::MAX (callers map this to a decimal-limit Veto).
Sourcepub fn try_measure_canonical_as_decimal_in_unit(
&self,
canonical_magnitude: &RationalInteger,
unit_name: &str,
) -> Result<String, NumericFailure>
pub fn try_measure_canonical_as_decimal_in_unit( &self, canonical_magnitude: &RationalInteger, unit_name: &str, ) -> Result<String, NumericFailure>
Convert a canonical measure magnitude in the named declared unit to an API decimal string.
Sourcepub fn try_ratio_canonical_as_decimal_in_unit(
&self,
canonical_magnitude: &RationalInteger,
unit_name: &str,
) -> Result<String, NumericFailure>
pub fn try_ratio_canonical_as_decimal_in_unit( &self, canonical_magnitude: &RationalInteger, unit_name: &str, ) -> Result<String, NumericFailure>
Convert a canonical ratio magnitude in the named declared unit to an API decimal string.
Sourcepub fn example_value(&self) -> &'static str
pub fn example_value(&self) -> &'static str
Get an example value string for this type, suitable for UI help text
Sourcepub fn measure_type_decomposition(&self) -> Option<&BTreeMap<String, i32>>
pub fn measure_type_decomposition(&self) -> Option<&BTreeMap<String, i32>>
Factor for a unit of this measure type (for unit conversion during evaluation only).
Planning must validate conversions first and return Error for invalid units.
If called with a non-measure type or unknown unit name, panics (invariant violation).
Returns the resolved BaseMeasureVector for Measure types, or None if
the decomposition pass has not yet resolved this type.
Panics if called on non-Measure types.
Sourcepub fn measure_runtime_signature(&self) -> Vec<(String, i32)>
pub fn measure_runtime_signature(&self) -> Vec<(String, i32)>
Runtime unit signature for measure arithmetic and display.
- Named measure with units:
[(canonical_or_first_unit_name, 1)]. Arithmetic expands this viaexpand_signature_to_base_unitsusing the unit table. - Anonymous / no units: decomposition converted to signature form.
Sourcepub fn ratio_primary_unit(&self) -> Option<&str>
pub fn ratio_primary_unit(&self) -> Option<&str>
Primary declared ratio unit name when the type carries a non-empty unit table.
Sourcepub fn is_anonymous_measure(&self) -> bool
pub fn is_anonymous_measure(&self) -> bool
Returns true if this is an anonymous (no-name) Measure — i.e. an anonymous intermediate produced by cross-axis arithmetic.
Sourcepub fn anonymous_for_decomposition(decomposition: BTreeMap<String, i32>) -> Self
pub fn anonymous_for_decomposition(decomposition: BTreeMap<String, i32>) -> Self
Build an anonymous LemmaType for a given dimensional decomposition.
Used at plan time to represent the inferred type of cross-axis intermediates.
Runtime unit signature is derived from this decomposition via
LemmaType::measure_runtime_signature.
Sourcepub fn ratio_unit_names(&self) -> Option<Vec<&str>>
pub fn ratio_unit_names(&self) -> Option<Vec<&str>>
Declared ratio unit names when the type carries a non-empty unit table (None otherwise).
Sourcepub fn measure_unit_names(&self) -> Option<Vec<&str>>
pub fn measure_unit_names(&self) -> Option<Vec<&str>>
Declared unit names when the type carries a non-empty unit table (None otherwise).
Sourcepub fn label_for_data_input(&self, input_key: &str) -> String
pub fn label_for_data_input(&self, input_key: &str) -> String
age [number] or gender [gender_code] — brackets omitted when type adds nothing.
Sourcepub fn data_veto_message(&self, input_key: &str, detail: &str) -> String
pub fn data_veto_message(&self, input_key: &str, detail: &str) -> String
Data age [number]: {detail} for runtime data override vetoes.
Sourcepub fn empty_runtime_input_vetoes(&self) -> bool
pub fn empty_runtime_input_vetoes(&self) -> bool
Whether an empty [RunDataValue] should veto before parse (text may accept "").
Sourcepub fn measure_unit_factor(&self, unit_name: &str) -> &RationalInteger
pub fn measure_unit_factor(&self, unit_name: &str) -> &RationalInteger
Return the conversion factor for a declared unit name on this measure type.
pub fn ratio_unit_factor(&self, unit_name: &str) -> &RationalInteger
Trait Implementations§
Source§impl<'de> Deserialize<'de> for LemmaType
impl<'de> Deserialize<'de> for LemmaType
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
impl Eq for LemmaType
Source§impl From<&LemmaType> for LemmaType
impl From<&LemmaType> for LemmaType
Source§fn from(lemma_type: &DomainLemmaType) -> Self
fn from(lemma_type: &DomainLemmaType) -> Self
impl StructuralPartialEq for LemmaType
Auto Trait Implementations§
impl Freeze for LemmaType
impl RefUnwindSafe for LemmaType
impl Send for LemmaType
impl Sync for LemmaType
impl Unpin for LemmaType
impl UnsafeUnpin for LemmaType
impl UnwindSafe for LemmaType
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.