Expr

Struct Expr 

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

A CEL expression node in the abstract syntax tree.

Expr represents a single node in a CEL expression tree during macro expansion. Each expression has a unique ID for source location tracking and an optional kind that determines what type of expression it is (constant, function call, etc.).

§Structure

An expression consists of:

  • id: A unique identifier for source position tracking and error reporting
  • kind: The specific type and content of the expression (or None for unspecified)

§Expression Kinds

The kind field determines the expression type:

§Examples

// Access expression properties
let id = expr.id();
 
// Check expression kind
if let Some(kind) = expr.kind() {
    match kind {
        ExprKind::Constant(c) => println!("Constant: {:?}", c),
        ExprKind::Ident(i) => println!("Identifier: {}", i.name),
        ExprKind::Call(c) => println!("Function: {}", c.function),
        _ => {}
    }
}

Implementations§

Source§

impl Expr

Source

pub fn id(&self) -> i64

Returns the unique identifier of this expression.

Expression IDs are used for source location tracking and correlating expressions with their positions in the original source code.

Source

pub fn set_id(&mut self, id: i64)

Sets the unique identifier of this expression.

This is typically handled by expression factory methods and rarely needs to be called directly in user code.

Source

pub fn kind(&self) -> Option<&ExprKind>

Returns a reference to the expression kind, if set.

Returns None for unspecified expressions (expressions without a kind set).

§Examples
if let Some(kind) = expr.kind() {
    if kind.is_constant() {
        println!("This is a constant expression");
    }
}
Source

pub fn set_kind(&mut self, kind: ExprKind)

Sets the expression kind.

This replaces any existing kind with the new one. Use this to construct or modify expressions during macro expansion.

Source

pub fn clear_kind(&mut self)

Clears the expression kind, making this an unspecified expression.

This is rarely needed in practice; most expressions should have a kind.

Methods from Deref<Target = ExprKind>§

Source

pub fn is_constant(&self) -> bool

Returns true if this is a constant expression.

Source

pub fn is_ident(&self) -> bool

Returns true if this is an identifier expression.

Source

pub fn is_select(&self) -> bool

Returns true if this is a select expression.

Source

pub fn is_call(&self) -> bool

Returns true if this is a call expression.

Source

pub fn is_list(&self) -> bool

Returns true if this is a list expression.

Source

pub fn is_struct(&self) -> bool

Returns true if this is a struct expression.

Source

pub fn is_map(&self) -> bool

Returns true if this is a map expression.

Source

pub fn is_comprehension(&self) -> bool

Returns true if this is a comprehension expression.

Source

pub fn as_constant(&self) -> Option<&Constant>

Returns a reference to the constant value if this is a constant expression.

Source

pub fn as_ident(&self) -> Option<&IdentExpr>

Returns a reference to the identifier if this is an identifier expression.

Source

pub fn as_select(&self) -> Option<&SelectExpr>

Returns a reference to the select expression if this is a select expression.

Source

pub fn as_call(&self) -> Option<&CallExpr>

Returns a reference to the call expression if this is a call expression.

Source

pub fn as_list(&self) -> Option<&ListExpr>

Returns a reference to the list expression if this is a list expression.

Source

pub fn as_struct(&self) -> Option<&StructExpr>

Returns a reference to the struct expression if this is a struct expression.

Source

pub fn as_map(&self) -> Option<&MapExpr>

Returns a reference to the map expression if this is a map expression.

Source

pub fn as_comprehension(&self) -> Option<&ComprehensionExpr>

Returns a reference to the comprehension expression if this is a comprehension expression.

Source

pub fn as_constant_mut(&mut self) -> Option<&mut Constant>

Returns a mutable reference to the constant value if this is a constant expression.

Source

pub fn as_ident_mut(&mut self) -> Option<&mut IdentExpr>

Returns a mutable reference to the identifier if this is an identifier expression.

Source

pub fn as_select_mut(&mut self) -> Option<&mut SelectExpr>

Returns a mutable reference to the select expression if this is a select expression.

Source

pub fn as_call_mut(&mut self) -> Option<&mut CallExpr>

Returns a mutable reference to the call expression if this is a call expression.

Source

pub fn as_list_mut(&mut self) -> Option<&mut ListExpr>

Returns a mutable reference to the list expression if this is a list expression.

Source

pub fn as_struct_mut(&mut self) -> Option<&mut StructExpr>

Returns a mutable reference to the struct expression if this is a struct expression.

Source

pub fn as_map_mut(&mut self) -> Option<&mut MapExpr>

Returns a mutable reference to the map expression if this is a map expression.

Source

pub fn as_comprehension_mut(&mut self) -> Option<&mut ComprehensionExpr>

Returns a mutable reference to the comprehension expression if this is a comprehension expression.

Trait Implementations§

Source§

impl Debug for Expr

Source§

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

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

impl Default for Expr

Source§

fn default() -> Expr

Returns the “default value” for a type. Read more
Source§

impl Deref for Expr

Source§

type Target = ExprKind

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Self::Target

Dereferences the value.
Source§

impl DerefMut for Expr

Source§

fn deref_mut(&mut self) -> &mut Self::Target

Mutably dereferences the value.
Source§

impl From<&Expr> for Expr

Source§

fn from(value: &Expr) -> Self

Converts to this type from the input type.
Source§

impl From<&Expr> for UniquePtr<Expr>

Source§

fn from(value: &Expr) -> Self

Converts to this type from the input type.
Source§

impl From<Expr> for UniquePtr<Expr>

Source§

fn from(value: Expr) -> Self

Converts to this type from the input type.
Source§

impl From<UniquePtr<Expr>> for Expr

Source§

fn from(value: UniquePtr<Expr>) -> Self

Converts to this type from the input type.

Auto Trait Implementations§

§

impl Freeze for Expr

§

impl RefUnwindSafe for Expr

§

impl Send for Expr

§

impl Sync for Expr

§

impl Unpin for Expr

§

impl UnwindSafe for Expr

Blanket Implementations§

§

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

§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

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

§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
§

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

§

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

Mutably borrows from an owned value. Read more
§

impl<T> From<T> for T

§

fn from(t: T) -> T

Returns the argument unchanged.

§

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

§

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
§

impl<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
§

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

§

type Error = Infallible

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

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

Performs the conversion.
§

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

§

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

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

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

Performs the conversion.