Skip to main content

Ty

Enum Ty 

Source
pub enum Ty {
Show 21 variants I8, I16, I32, I64, I128, Isize, U8, U16, U32, U64, U128, Usize, F32, F64, Bool, String, Array(Box<Ty>), Tuple(Vec<Ty>), Callable(Vec<Ty>, Box<Ty>), Registered(ResolvedLeafType), Any,
}
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

Source

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

pub fn from_literal(lit: &Literal) -> Ty

Maps a resolved Literal to its exact primitive or registered leaf identity.

§Examples
use cel_parser::{Literal, Ty};

assert_eq!(Ty::from_literal(&Literal::I32(1)), Ty::I32);
assert_eq!(Ty::from_literal(&Literal::Unit).type_id(), Some(std::any::TypeId::of::<()>()));
Source

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

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

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

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

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

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 (when Some) unifies with both self and other.
  • 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);

Trait Implementations§

Source§

impl Clone for Ty

Source§

fn clone(&self) -> Ty

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 Debug for Ty

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Eq for Ty

Source§

impl PartialEq for Ty

Source§

fn eq(&self, other: &Ty) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for Ty

Auto Trait Implementations§

§

impl Freeze for Ty

§

impl RefUnwindSafe for Ty

§

impl Send for Ty

§

impl Sync for Ty

§

impl Unpin for Ty

§

impl UnsafeUnpin for Ty

§

impl UnwindSafe for Ty

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.