pub struct Comprehension {
pub iter_var: String,
pub iter_var2: String,
pub iter_range: Option<Box<Expr>>,
pub accu_var: String,
pub accu_init: Option<Box<Expr>>,
pub loop_condition: Option<Box<Expr>>,
pub loop_step: Option<Box<Expr>>,
pub result: Option<Box<Expr>>,
}Expand description
A comprehension expression applied to a list or map.
Comprehensions are not part of the core syntax, but enabled with macros. A macro matches a specific call signature within a parsed AST and replaces the call with an alternate AST block. Macro expansion happens at parse time.
The following macros are supported within CEL:
Aggregate type macros may be applied to all elements in a list or all keys in a map:
all,exists,exists_one- test a predicate expression against the inputs and returntrueif the predicate is satisfied for all, any, or only one valuelist.all(x, x < 10).filter- test a predicate expression against the inputs and return the subset of elements which satisfy the predicate:payments.filter(p, p > 1000).map- apply an expression to all elements in the input and return the output aggregate type:\[1, 2, 3\].map(i, i * i).
The has(m.x) macro tests whether the property x is present in struct
m. The semantics of this macro depend on the type of m. For proto2
messages has(m.x) is defined as ’defined, but not set. For proto3, the macro tests whether the property is set to its default. For map and struct types, the macro tests whether the property xis defined onm`.
Comprehensions for the standard environment macros evaluation can be best visualized as the following pseudocode:
let `accu_var` = `accu_init`
for (let `iter_var` in `iter_range`) {
if (!`loop_condition`) {
break
}
`accu_var` = `loop_step`
}
return `result`Comprehensions for the optional V2 macros which support map-to-map translation differ slightly from the standard environment macros in that they expose both the key or index in addition to the value for each list or map entry:
let `accu_var` = `accu_init`
for (let `iter_var`, `iter_var2` in `iter_range`) {
if (!`loop_condition`) {
break
}
`accu_var` = `loop_step`
}
return `result`Fields§
§iter_var: StringThe name of the first iteration variable. When the iter_range is a list, this variable is the list element. When the iter_range is a map, this variable is the map entry key.
iter_var2: StringThe name of the second iteration variable, empty if not set. When the iter_range is a list, this variable is the integer index. When the iter_range is a map, this variable is the map entry value. This field is only set for comprehension v2 macros.
iter_range: Option<Box<Expr>>The range over which the comprehension iterates.
accu_var: StringThe name of the variable used for accumulation of the result.
accu_init: Option<Box<Expr>>The initial value of the accumulator.
loop_condition: Option<Box<Expr>>An expression which can contain iter_var, iter_var2, and accu_var.
Returns false when the result has been computed and may be used as a hint to short-circuit the remainder of the comprehension.
loop_step: Option<Box<Expr>>An expression which can contain iter_var, iter_var2, and accu_var.
Computes the next value of accu_var.
result: Option<Box<Expr>>An expression which can contain accu_var.
Computes the result.
Trait Implementations§
Source§impl Clone for Comprehension
impl Clone for Comprehension
Source§fn clone(&self) -> Comprehension
fn clone(&self) -> Comprehension
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for Comprehension
impl Debug for Comprehension
Source§impl Default for Comprehension
impl Default for Comprehension
Source§impl Message for Comprehension
impl Message for Comprehension
Source§fn encoded_len(&self) -> usize
fn encoded_len(&self) -> usize
Source§fn encode(&self, buf: &mut impl BufMut) -> Result<(), EncodeError>where
Self: Sized,
fn encode(&self, buf: &mut impl BufMut) -> Result<(), EncodeError>where
Self: Sized,
Source§fn encode_to_vec(&self) -> Vec<u8> ⓘwhere
Self: Sized,
fn encode_to_vec(&self) -> Vec<u8> ⓘwhere
Self: Sized,
Source§fn encode_length_delimited(
&self,
buf: &mut impl BufMut,
) -> Result<(), EncodeError>where
Self: Sized,
fn encode_length_delimited(
&self,
buf: &mut impl BufMut,
) -> Result<(), EncodeError>where
Self: Sized,
Source§fn encode_length_delimited_to_vec(&self) -> Vec<u8> ⓘwhere
Self: Sized,
fn encode_length_delimited_to_vec(&self) -> Vec<u8> ⓘwhere
Self: Sized,
Source§fn decode(buf: impl Buf) -> Result<Self, DecodeError>where
Self: Default,
fn decode(buf: impl Buf) -> Result<Self, DecodeError>where
Self: Default,
Source§fn decode_length_delimited(buf: impl Buf) -> Result<Self, DecodeError>where
Self: Default,
fn decode_length_delimited(buf: impl Buf) -> Result<Self, DecodeError>where
Self: Default,
Source§fn merge(&mut self, buf: impl Buf) -> Result<(), DecodeError>where
Self: Sized,
fn merge(&mut self, buf: impl Buf) -> Result<(), DecodeError>where
Self: Sized,
self. Read moreSource§fn merge_length_delimited(&mut self, buf: impl Buf) -> Result<(), DecodeError>where
Self: Sized,
fn merge_length_delimited(&mut self, buf: impl Buf) -> Result<(), DecodeError>where
Self: Sized,
self.