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 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 only the name-to-descriptor metadata CEL needs for typed array
annotations, keeping sheet construction and other Adam-specific function pointers out of
cel-parser.
- Complexity: O(n + b) time and space for n registered names totaling b bytes.
§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,
)
pub fn register<T: Any + PartialEq + Default + Clone + Debug + 'static>( &mut self, name: &str, )
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. - Complexity: O(n + k) time and O(k) new name space for n registrations and k copied or compared name bytes.
§Examples
use adam_lang::TypeRegistry;
let mut reg = TypeRegistry::new();
reg.register::<u64>("my_u64");
assert!(reg.get("my_u64").is_some());Sourcepub fn register_no_default<T: Any + PartialEq + Clone + Debug + 'static>(
&mut self,
name: &str,
)
pub fn register_no_default<T: Any + PartialEq + Clone + Debug + 'static>( &mut self, name: &str, )
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. - Complexity: O(n + k) time and O(k) new name space for n registrations and k copied or compared name bytes.
§Examples
use adam_lang::TypeRegistry;
#[derive(PartialEq, Clone, Debug)]
struct MyType(i32);
let mut reg = TypeRegistry::new();
reg.register_no_default::<MyType>("MyType");
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 generic leaves use their complete source name, e.g. RangeInclusive(i32).
- 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: O(n) in generic argument nodes and name bytes.