pub struct TypeRegistry { /* private fields */ }Expand description
Registry for managing and resolving custom types
Types are organized per document and support inheritance through parent references. The registry handles cycle detection and accumulates overrides through the inheritance chain.
Implementations§
Source§impl TypeRegistry
impl TypeRegistry
Sourcepub fn register_type(
&mut self,
doc: &str,
def: TypeDef,
) -> Result<(), LemmaError>
pub fn register_type( &mut self, doc: &str, def: TypeDef, ) -> Result<(), LemmaError>
Register a user-defined type for a given document
Sourcepub fn resolve_types(
&self,
doc: &str,
) -> Result<ResolvedDocumentTypes, LemmaError>
pub fn resolve_types( &self, doc: &str, ) -> Result<ResolvedDocumentTypes, LemmaError>
Resolve all types for a certain document
Returns fully resolved types for the document, including named types, inline type definitions,
and a unit index. After resolution, all imports are inlined - documents are independent.
Follows parent chains, accumulates overrides into specifications.
Handles cycle detection and cross-document references.
§Errors
Returns an error if a unit appears in multiple types within the same document (ambiguous unit).
Sourcepub fn resolve_named_types(
&self,
doc: &str,
) -> Result<ResolvedDocumentTypes, LemmaError>
pub fn resolve_named_types( &self, doc: &str, ) -> Result<ResolvedDocumentTypes, LemmaError>
Resolve only named types (for validation before inline type definitions are registered)
Sourcepub fn resolve_standard_type(&self, name: &str) -> Option<TypeSpecification>
pub fn resolve_standard_type(&self, name: &str) -> Option<TypeSpecification>
Resolve a standard type by name
Sourcepub fn find_document_for_fact(&self, fact_ref: &FactReference) -> Option<String>
pub fn find_document_for_fact(&self, fact_ref: &FactReference) -> Option<String>
Find which document a FactReference belongs to (for inline type definitions)
Sourcepub fn get_all_units(&self) -> HashMap<String, Vec<(String, String)>>
pub fn get_all_units(&self) -> HashMap<String, Vec<(String, String)>>
Get all units defined across all types, organized by unit name
Returns a map from unit name to a list of (document_name, type_name) pairs where that unit is defined. Useful for error messages and debugging.
§Returns
A HashMap where:
- Key: unit name (e.g., “celsius”, “kilogram”)
- Value: list of (document_name, type_name) pairs where the unit is defined
Trait Implementations§
Source§impl Clone for TypeRegistry
impl Clone for TypeRegistry
Source§fn clone(&self) -> TypeRegistry
fn clone(&self) -> TypeRegistry
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for TypeRegistry
impl Debug for TypeRegistry
Auto Trait Implementations§
impl Freeze for TypeRegistry
impl RefUnwindSafe for TypeRegistry
impl Send for TypeRegistry
impl Sync for TypeRegistry
impl Unpin for TypeRegistry
impl UnwindSafe for TypeRegistry
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<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