ComprehensionExpr

Struct ComprehensionExpr 

Source
pub struct ComprehensionExpr {
    pub iter_var: String,
    pub iter_var2: String,
    pub iter_range: Expr,
    pub accu_var: String,
    pub accu_init: Expr,
    pub loop_condition: Expr,
    pub loop_step: Expr,
    pub result: Expr,
}
Expand description

A comprehension expression for list/map processing.

Comprehensions are CEL’s powerful iteration construct, similar to list comprehensions in Python. They consist of iteration, accumulation, and result computation phases.

§Structure

A comprehension has:

  • One or two iteration variables that range over a collection
  • An accumulator variable that maintains state across iterations
  • A loop condition that determines when to continue
  • A loop step that updates the accumulator
  • A result expression that produces the final value

§Examples

Single variable: [x * 2 | x in [1, 2, 3]]

  • iter_var: "x"
  • iter_range: [1, 2, 3]
  • Result: [2, 4, 6]

Two variables (map iteration): [k | k, v in {"a": 1, "b": 2}, v > 1]

  • iter_var: "k" (key)
  • iter_var2: "v" (value)
  • iter_range: {"a": 1, "b": 2}
  • Result: ["b"]

Fields§

§iter_var: String

The first iteration variable name (required).

§iter_var2: String

The second iteration variable name (empty string if not used).

§iter_range: Expr

The expression providing the collection to iterate over.

§accu_var: String

The accumulator variable name.

§accu_init: Expr

The initial value of the accumulator.

§loop_condition: Expr

The condition to continue iterating (often just true).

§loop_step: Expr

The expression to update the accumulator each iteration.

§result: Expr

The final expression computed from the accumulator.

Trait Implementations§

Source§

impl Debug for ComprehensionExpr

Source§

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

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

impl From<&ComprehensionExpr> for ComprehensionExpr

Source§

fn from(value: &ComprehensionExpr) -> Self

Converts to this type from the input type.
Source§

impl From<UniquePtr<ComprehensionExpr>> for ComprehensionExpr

Source§

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

Converts to this type from the input type.

Auto Trait Implementations§

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<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.