Skip to main content

TypeRegistry

Struct TypeRegistry 

Source
pub struct TypeRegistry { /* private fields */ }
Expand description

Maps DSL type names to Rust types for adam-lang cell declarations.

§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

Source

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) in the number of registered leaf types.
Source

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.

Source

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) returns Some(entry) with entry.default_fn.is_some().
§Examples
use adam_lang::TypeRegistry;
let mut reg = TypeRegistry::new();
reg.register::<u64>("my_u64");
assert!(reg.get("my_u64").is_some());
Source

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) returns Some(entry) with entry.default_fn.is_none().
§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());
Source

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.

§Examples
use adam_lang::TypeRegistry;
let reg = TypeRegistry::new();
assert!(reg.get("f64").is_some());
assert!(reg.get("nonexistent").is_none());
Source

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.

§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());
Source

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(&registry.resolve(&ty).unwrap()), "[(i32, [f64])]");
Source

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);
Source

pub fn display_name(&self, shape: &TypeShape) -> String

Formats shape recursively, e.g. "(i32, (f64, String))", for error messages.

Trait Implementations§

Source§

impl Clone for TypeRegistry

Source§

fn clone(&self) -> TypeRegistry

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Default for TypeRegistry

Source§

fn default() -> Self

Returns TypeRegistry::new().

Source§

impl TypeResolver for TypeRegistry

Source§

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.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.