pub struct LemmaType {
pub name: Option<String>,
pub specifications: TypeSpecification,
pub extends: TypeExtends,
}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, Quantity, etc.).
Serialized as a discriminated union: the variant tag appears as
"kind" alongside name and extends, and the variant’s fields
are flattened to the top level.
extends: TypeExtendsWhat this type extends (primitive or custom from a spec)
Implementations§
Source§impl LemmaType
impl LemmaType
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 is_boolean(&self) -> bool
pub fn is_boolean(&self) -> bool
Check if this type is boolean
Sourcepub fn is_quantity(&self) -> bool
pub fn is_quantity(&self) -> bool
Check if this type is quantity
pub fn is_quantity_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 quantity or number)
pub fn is_date_range(&self) -> bool
pub fn has_trait_duration(&self) -> bool
pub fn is_duration_like_quantity(&self) -> bool
pub fn is_duration_like(&self) -> bool
Sourcepub fn is_calendar(&self) -> bool
pub fn is_calendar(&self) -> bool
Check if this type is calendar
pub fn is_ratio_range(&self) -> bool
pub fn is_calendar_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 quantity_family_name(&self) -> Option<&str>
pub fn quantity_family_name(&self) -> Option<&str>
For quantity 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-quantity types, returns None.
Sourcepub fn same_quantity_family(&self, other: &LemmaType) -> bool
pub fn same_quantity_family(&self, other: &LemmaType) -> bool
Returns true if both types are quantity and belong to the same named quantity family.
pub fn compatible_with_anonymous_quantity(&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, Quantity, and Ratio). Used by formatters. Ratio: optional, no default; when None display is normalized (no trailing zeros).
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 quantity_type_decomposition(&self) -> &BaseQuantityVector
pub fn quantity_type_decomposition(&self) -> &BaseQuantityVector
Factor for a unit of this quantity type (for unit conversion during evaluation only).
Planning must validate conversions first and return Error for invalid units.
If called with a non-quantity type or unknown unit name, panics (invariant violation).
Returns the BaseQuantityVector for Quantity types.
For base quantitys (after decomposition pass) this is {type_name: 1}.
For derived quantitys it is the combined dimensional vector.
Panics if called on non-Quantity types.
Sourcepub fn is_anonymous_quantity(&self) -> bool
pub fn is_anonymous_quantity(&self) -> bool
Returns true if this is an anonymous (no-name) Quantity — i.e. an anonymous intermediate produced by cross-axis arithmetic.
Sourcepub fn anonymous_for_decomposition(decomposition: BaseQuantityVector) -> Self
pub fn anonymous_for_decomposition(decomposition: BaseQuantityVector) -> Self
Build an anonymous LemmaType for a given dimensional decomposition.
Used at plan time to represent the inferred type of cross-axis intermediates.
Sourcepub fn quantity_unit_names(&self) -> Option<Vec<&str>>
pub fn quantity_unit_names(&self) -> Option<Vec<&str>>
Declared unit names for a named quantity type (None for non-quantity or anonymous quantity).
Sourcepub fn validate_quantity_result_unit(
&self,
target_unit: &str,
) -> Result<(), String>
pub fn validate_quantity_result_unit( &self, target_unit: &str, ) -> Result<(), String>
Whether a value of this type may be expressed in target_unit (typed named quantity only).
Used by planning (as on typed quantity operands) and evaluation API rule-result conversion.
Sourcepub fn validate_rule_result_unit_conversion(
&self,
target_unit: &str,
unit_index: &HashMap<String, LemmaType>,
spec_name: &str,
) -> Result<SemanticConversionTarget, String>
pub fn validate_rule_result_unit_conversion( &self, target_unit: &str, unit_index: &HashMap<String, LemmaType>, spec_name: &str, ) -> Result<SemanticConversionTarget, String>
Whether source_type may be converted to target_unit for as / API rule-result display.
Mirrors planning check_unit_conversion_types for quantity- and
ratio-unit targets. Callers must reject impossible conversions before evaluation.
pub fn quantity_unit_factor(&self, unit_name: &str) -> &RationalInteger
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
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,
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.Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more