pub enum Ty {
}Expand description
A complete recursive source type, or an unresolved editor value.
Variants§
I8
i8.
I16
i16.
I32
i32.
I64
i64.
I128
i128.
Isize
isize.
U8
u8.
U16
u16.
U32
u32.
U64
u64.
U128
u128.
Usize
usize.
F32
f32.
F64
f64.
Bool
bool.
String
String.
Array(Box<Ty>)
A canonical homogeneous array of the boxed element type, which may
itself be an array ([[i32]]) or Ty::Any (an array whose element type isn’t
statically known — e.g. [f(), g()], whose elements are unresolved call results).
Tuple(Vec<Ty>)
A source-ordered tuple, including unit and singleton tuples.
Callable(Vec<Ty>, Box<Ty>)
A callable with complete parameter and result types.
Registered(ResolvedLeafType)
A known leaf, retaining its concrete identity and complete runtime descriptor. Registered function markers are callable only through their registered identity; other leaves, including builtin ranges and foreign values, are not callable.
Any
Anything not statically known: an unannotated cell, an
unresolved identifier, or a call without available metadata.
Unifies silently with every other Ty, in both directions.
Implementations§
Source§impl Ty
impl Ty
Sourcepub fn from_leaf(leaf: &ResolvedLeafType) -> Self
pub fn from_leaf(leaf: &ResolvedLeafType) -> Self
Preserves a resolved leaf descriptor, using primitive and recursive array variants.
- Complexity: O(d + l) in descriptor depth d and leaf display-name length l.
§Examples
use cel_parser::{ResolvedLeafType, Ty};
use cel_runtime::ValueType;
let leaf = ResolvedLeafType::new("custom", ValueType::leaf::<()>());
assert_eq!(Ty::from_leaf(&leaf), Ty::Registered(leaf));Sourcepub fn from_literal(lit: &Literal) -> Ty
pub fn from_literal(lit: &Literal) -> Ty
Sourcepub fn from_type_id(id: TypeId) -> Ty
pub fn from_type_id(id: TypeId) -> Ty
Maps a TypeId (e.g. from adam_lang::TypeRegistry::TypeEntry::type_id) to its Ty.
An unrecognized TypeId maps to Ty::Any — not an error, matching adam-lang/CEL’s
extensible type system (a host binary’s custom registered types are invisible here).
A flat TypeId never establishes a structural array shape; structural
identities require recursive descriptors instead.
§Examples
use std::any::TypeId;
use cel_parser::Ty;
assert_eq!(Ty::from_type_id(TypeId::of::<i32>()), Ty::I32);
assert_eq!(Ty::from_type_id(TypeId::of::<Vec<u8>>()), Ty::Any);
assert_eq!(
Ty::from_type_id(TypeId::of::<cel_runtime::OwnedValue>()),
Ty::Any
);Sourcepub fn type_id(&self) -> Option<TypeId>
pub fn type_id(&self) -> Option<TypeId>
Returns this type’s TypeId, or None for Ty::Any and nonempty tuples (whose
storage needs a complete shape), and arrays, whose elements also need a complete shape.
§Examples
use std::any::TypeId;
use cel_parser::Ty;
assert_eq!(Ty::I32.type_id(), Some(TypeId::of::<i32>()));
assert_eq!(Ty::Any.type_id(), None);
assert_eq!(
Ty::Array(Box::new(Ty::I32)).type_id(),
None
);Sourcepub fn name(&self) -> Cow<'_, str>
pub fn name(&self) -> Cow<'_, str>
Returns a human-readable name for diagnostics, borrowing primitive and leaf names.
- Complexity: O(n * l) time and O(l) space for n recursive nodes and l output bytes; primitive and registered leaf names take O(1).
§Examples
use cel_parser::Ty;
assert_eq!(Ty::I32.name(), "i32");
assert_eq!(Ty::Any.name(), "<any>");
assert_eq!(Ty::Array(Box::new(Ty::Array(Box::new(Ty::I32)))).name(), "[[i32]]");Sourcepub fn from_name(name: &str) -> Option<Ty>
pub fn from_name(name: &str) -> Option<Ty>
Maps a type’s bare name (as written in source, e.g. in a cast’s target position) to its
Ty, or None if name isn’t a recognized primitive - the inverse of Ty::name,
except it has no input that maps to Ty::Any (nothing is spelled <any> in source).
§Examples
use cel_parser::Ty;
assert_eq!(Ty::from_name("i32"), Some(Ty::I32));
assert_eq!(Ty::from_name("nonsense"), None);Sourcepub fn unifies_with(&self, other: &Ty) -> bool
pub fn unifies_with(&self, other: &Ty) -> bool
Returns true if self and other have compatible recursive shapes.
Ty::Any unifying silently with everything (in both directions and at every nesting level) is the
load-bearing property that lets unresolved inputs produce zero false-positive diagnostics.
Registered leaves unify only when their complete descriptors agree, regardless of aliases.
- Complexity: O(n + l) time and space for n recursive nodes and l registered name bytes.
§Examples
use cel_parser::Ty;
assert!(Ty::Any.unifies_with(&Ty::I32));
assert!(!Ty::I32.unifies_with(&Ty::F64));
assert!(Ty::Array(Box::new(Ty::Any)).unifies_with(&Ty::Array(Box::new(Ty::I32))));
assert!(!Ty::Array(Box::new(Ty::I32)).unifies_with(&Ty::Array(Box::new(Ty::F64))));Sourcepub fn unify(&self, other: &Ty) -> Option<Ty>
pub fn unify(&self, other: &Ty) -> Option<Ty>
The most specific type both self and other describe, or None if they’re
incompatible: Ty::Any yields the other side (it constrains nothing); arrays,
tuples, and callables unify recursively with equal arity; equal leaves yield themselves.
- Postcondition:
self.unify(other).is_some() == self.unifies_with(other), and the result (whenSome) unifies with bothselfandother. - Complexity: O(n + l) time and space for n recursive nodes and l registered name bytes.
§Examples
use cel_parser::Ty;
assert_eq!(Ty::Any.unify(&Ty::I32), Some(Ty::I32));
assert_eq!(
Ty::Array(Box::new(Ty::Any)).unify(&Ty::Array(Box::new(Ty::I32))),
Some(Ty::Array(Box::new(Ty::I32)))
);
assert_eq!(Ty::I32.unify(&Ty::F64), None);