pub struct TypeRegistry { /* private fields */ }Expand description
Maps DSL type names to Rust types for adam-lang cell declarations.
Every registered concrete type remains reverse-reachable while at least one of its names survives. Registering a new alias makes it the preferred reverse name; replacing that alias selects a surviving name if one exists.
§Example
use adam_lang::TypeRegistry;
let mut reg = TypeRegistry::new();
assert!(reg.get("i32").is_some());
assert!(reg.get("unknown").is_none());Implementations§
Source§impl TypeRegistry
impl TypeRegistry
Sourcepub fn register_type_function(
&mut self,
name: &str,
arguments: &[ResolvedType],
result: ResolvedLeafType,
) -> Result<(), TypeFunctionError>
pub fn register_type_function( &mut self, name: &str, arguments: &[ResolvedType], result: ResolvedLeafType, ) -> Result<(), TypeFunctionError>
Registers a finite nominal application independently of argument spellings.
This does not register its result for Adam cell storage.
§Errors
Rejects invalid names, incomplete descriptors, and conflicting results.
- Complexity: Expected O(n + r) time and peak space for new descriptor/name area n and combined old/new retained descriptor area r.
§Examples
use adam_lang::TypeRegistry;
use cel_parser::ResolvedLeafType;
let mut types = TypeRegistry::new();
types.register_type_function("Bounds", &[
ResolvedLeafType::leaf::<i32>("Integer").unwrap().into()
], ResolvedLeafType::leaf::<std::ops::Range<i32>>("Bounds").unwrap()).unwrap();
assert!(types.type_functions().signatures().any(|signature| signature.name == "Bounds"));Sourcepub fn type_functions(&self) -> &TypeFunctionRegistry
pub fn type_functions(&self) -> &TypeFunctionRegistry
Borrows builtin and application overloads with their effective nominal descriptors.
§Examples
Sourcepub fn cel_type_resolver(&self) -> RegistryTypeResolver
pub fn cel_type_resolver(&self) -> RegistryTypeResolver
Builds a CEL-facing resolver snapshot from this registry’s registered leaf types.
The returned resolver owns leaf aliases and finite type-function descriptors,
keeping sheet construction and other Adam-specific function pointers out of
cel-parser.
- Complexity: O(n + a · d) time and O(n) result space for registration metadata area n, a aliases, and largest effective diagnostic name size d.
§Examples
use cel_parser::TypeResolver;
let registry = adam_lang::TypeRegistry::new();
let snapshot = registry.cel_type_resolver();
drop(registry);
assert!(snapshot.resolve_named_type("i32", &[]).is_some());Sourcepub fn new() -> Self
pub fn new() -> Self
Creates a registry pre-populated with all built-in CEL/Rust primitive types.
Registered types: i8, i16, i32, i64, i128, isize,
u8, u16, u32, u64, u128, usize, f32, f64, bool, String.
§Examples
let registry = adam_lang::TypeRegistry::new();
assert_eq!(registry.get("i32").unwrap().type_id, std::any::TypeId::of::<i32>());Sourcepub fn register<T: Any + PartialEq + Default + Clone + Debug + 'static>(
&mut self,
name: &str,
) -> Result<(), TypeFunctionError>
pub fn register<T: Any + PartialEq + Default + Clone + Debug + 'static>( &mut self, name: &str, ) -> Result<(), TypeFunctionError>
Registers T under name with default initialization support.
- Postcondition:
self.get(name)returnsSome(entry)withentry.default_fn.is_some(). Surviving aliases remain reachable by name and concrete type identity.
§Errors
Rejects a conflicting zero-operand type function or incompatible descriptor facts.
- Complexity: O(n + r + k) time and peak auxiliary space for n aliases, combined old/new retained descriptor area r, and copied or compared name bytes k.
§Examples
use adam_lang::TypeRegistry;
let mut reg = TypeRegistry::new();
reg.register::<u64>("my_u64").unwrap();
assert!(reg.get("my_u64").is_some());Sourcepub fn register_no_default<T: Any + PartialEq + Clone + Debug + 'static>(
&mut self,
name: &str,
) -> Result<(), TypeFunctionError>
pub fn register_no_default<T: Any + PartialEq + Clone + Debug + 'static>( &mut self, name: &str, ) -> Result<(), TypeFunctionError>
Registers T under name without default initialization support.
A cell declared as cell x: T; (no initializer) is a parse error for this type.
- Postcondition:
self.get(name)returnsSome(entry)withentry.default_fn.is_none(). Surviving aliases remain reachable by name and concrete type identity.
§Errors
Rejects a conflicting zero-operand type function or incompatible descriptor facts.
- Complexity: O(n + r + k) time and peak auxiliary space for n aliases, combined old/new retained descriptor area r, and copied or compared name bytes k.
§Examples
use adam_lang::TypeRegistry;
#[derive(PartialEq, Clone, Debug)]
struct MyType(i32);
let mut reg = TypeRegistry::new();
reg.register_no_default::<MyType>("MyType").unwrap();
let entry = reg.get("MyType").unwrap();
assert!(entry.default_fn.is_none());Sourcepub fn get(&self, name: &str) -> Option<&TypeEntry>
pub fn get(&self, name: &str) -> Option<&TypeEntry>
Looks up a type entry by its DSL name.
Returns None if name has not been registered.
- Complexity: expected O(k) time in k name bytes and O(1) space.
§Examples
use adam_lang::TypeRegistry;
let reg = TypeRegistry::new();
assert!(reg.get("f64").is_some());
assert!(reg.get("nonexistent").is_none());Sourcepub fn entry_by_type_id(&self, type_id: TypeId) -> Option<&TypeEntry>
pub fn entry_by_type_id(&self, type_id: TypeId) -> Option<&TypeEntry>
Looks up a type entry by its TypeId.
Returns None if no type with this TypeId has been registered.
- Complexity: expected O(k) time in the selected registered name’s k bytes and O(1) space.
§Examples
use adam_lang::TypeRegistry;
use std::any::TypeId;
let reg = TypeRegistry::new();
assert!(reg.entry_by_type_id(TypeId::of::<f64>()).is_some());
assert!(reg.entry_by_type_id(TypeId::of::<Vec<u8>>()).is_none());Sourcepub fn resolve(&self, expr: &TypeExpr) -> Result<TypeShape, (String, Span)>
pub fn resolve(&self, expr: &TypeExpr) -> Result<TypeShape, (String, Span)>
Resolves a parsed type_expr against this registry, recursively.
§Errors
Returns an unknown leaf name, malformed callable signature, or unrepresentable layout. Registered type functions select complete argument identities.
- Complexity: O(n) in type nodes and registered-name bytes.
§Examples
let registry = adam_lang::TypeRegistry::new();
let ty = cel_parser::CELParser::new(cel_parser::OpLookup::new())
.parse_type_expr_str("[(i32, [f64])]").unwrap();
assert_eq!(registry.display_name(®istry.resolve(&ty).unwrap()), "[(i32, [f64])]");Sourcepub fn registered_name(&self, type_id: TypeId) -> Option<&str>
pub fn registered_name(&self, type_id: TypeId) -> Option<&str>
Returns the DSL name type_id was registered under, or None if it is unregistered.
This is the name every diagnostic should use for a live value’s type: a TypeEntry’s own
type_name is the Rust type path (alloc::string::String), not the registered name.
§Examples
use adam_lang::TypeRegistry;
let reg = TypeRegistry::new();
assert_eq!(reg.registered_name(std::any::TypeId::of::<String>()), Some("String"));
assert_eq!(reg.registered_name(std::any::TypeId::of::<Vec<u8>>()), None);Sourcepub fn display_name(&self, shape: &TypeShape) -> String
pub fn display_name(&self, shape: &TypeShape) -> String
Formats shape recursively using registered leaf names, or ? for unknown leaves.
- Complexity: O(n + b) time for n shape nodes and b result bytes; O(b + d) space including the result and recursion depth d.
§Examples
use adam_lang::{TypeRegistry, type_registry::TypeShape};
let shape = TypeShape::Tuple(vec![TypeShape::Named(std::any::TypeId::of::<i32>())]);
assert_eq!(TypeRegistry::new().display_name(&shape), "(i32,)");Sourcepub fn validate_shape(&self, shape: &TypeShape) -> Result<()>
pub fn validate_shape(&self, shape: &TypeShape) -> Result<()>
Checks every registered leaf and representable compound layout without evaluation.
Callable signatures and empty arrays still require registered element leaves.
§Errors
Rejects unregistered leaves or unrepresentable tuple layouts.
- Complexity: O(n) descriptor nodes and space.
§Examples
use adam_lang::{TypeRegistry, type_registry::TypeShape};
let types = TypeRegistry::new();
assert!(types.validate_shape(&TypeShape::Array(Box::new(
TypeShape::Named(std::any::TypeId::of::<i32>())
))).is_ok());Trait Implementations§
Source§impl Clone for TypeRegistry
impl Clone for TypeRegistry
Source§impl TypeResolver for TypeRegistry
impl TypeResolver for TypeRegistry
Source§fn resolve_named_type(
&self,
name: &str,
args: &[ResolvedType],
) -> Option<ResolvedLeafType>
fn resolve_named_type( &self, name: &str, args: &[ResolvedType], ) -> Option<ResolvedLeafType>
Resolves a leaf without allocating a complete registry snapshot.
- Complexity: Expected O(n + r) time and peak space for argument/name area n and retained/result diagnostic name bytes r.