Skip to main content

TypeExpr

Enum TypeExpr 

pub enum TypeExpr {
    Named {
        name: String,
        args: Vec<TypeExpr>,
        span: ExprSpan,
    },
    Array {
        element: Box<TypeExpr>,
        span: ExprSpan,
    },
    Tuple {
        elements: Vec<TypeExpr>,
        span: ExprSpan,
    },
}
Expand description

type_expr = identifier | "(" [ type_expr ["," [ type_expr { "," type_expr } ]] ] ")".

() is the empty tuple type (0 elements); (T) is grouping (same as bare T — types have no precedence to disambiguate, but staying symmetric with cel_parser’s expression grammar costs nothing); (T,) is a 1-element tuple; (T, U, ...) is n-element, no trailing comma. Shared verbatim with cel_parser (which additionally supports [T] array types and Name(args) parameterized/generic types) so both crates resolve, format, and error on exactly one type-expression grammar. type_expression = identifier [ "(" [ type_expression { "," type_expression } ] ")" ] | "[" type_expression "]" | "(" [ type_expression ["," [ type_expression { "," type_expression } ]] ] ")".

() is the empty tuple type (0 elements); (T) is grouping (same as bare T); (T,) is a 1-element tuple; (T, U, ...) is n-element, no trailing comma. [T] names a rank-one array whose elements have type T; nested brackets compose recursively. Name(A, B) names a parameterized (generic) type applying zero or more type arguments (RangeInclusive(f64), RangeFull()); an identifier immediately followed by ( has no other meaning in type position, so this is unambiguous with adjacent tuple-grouping syntax. Fn((A, B), R) reserves structural callable syntax: the first argument must be a tuple of parameter types and the second is the result. Fn((), R) has no parameters; Fn((A,), R) has one. This syntax is resolved before host generic-leaf lookup.

Variants§

§

Named

A single type name, optionally applying type arguments, resolved later through a [TypeResolver].

Fields

§name: String

The unresolved type name, exactly as written.

§args: Vec<TypeExpr>

Type arguments, e.g. f64 in RangeInclusive(f64). Empty for a plain name.

§span: ExprSpan

The source span of the full name token, including any parenthesized argument list.

§

Array

A recursively nested array type expression ([T]).

Fields

§element: Box<TypeExpr>

The element type expression.

§span: ExprSpan

The span of the whole bracketed type.

§

Tuple

A recursively nested tuple type expression.

Fields

§elements: Vec<TypeExpr>

The tuple element type expressions, in source order.

§span: ExprSpan

The span of the whole parenthesized type.

Implementations§

§

impl TypeExpr

pub fn span(&self) -> ExprSpan

Returns this type expression’s source span.

pub fn resolve( &self, resolver: &dyn TypeResolver, ) -> Result<ResolvedType, ParseError>

Resolves every named leaf through resolver, preserving the recursive type shape.

§Errors

Returns Err if some named leaf is not recognized by resolver, or Fn lacks exactly two arguments with a tuple of parameter types first.

  • Complexity: O(n) in the number of nodes in this type tree.

Trait Implementations§

§

impl Clone for TypeExpr

§

fn clone(&self) -> TypeExpr

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
§

impl Debug for TypeExpr

§

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

Formats the value using the given formatter. Read more

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.