pub struct ForExpr {
pub key_var: Option<Identifier>,
pub value_var: Identifier,
pub collection_expr: Expression,
pub key_expr: Option<Expression>,
pub value_expr: Expression,
pub grouping: bool,
pub cond_expr: Option<Expression>,
}
Expand description
A for expression is a construct for constructing a collection by projecting the items from another collection.
Fields§
§key_var: Option<Identifier>
Optional name of the variable that will be temporarily assigned the key of each element during iteration. If the source collection is an array, it gets assigned the zero-based array index. For an object source collection, this gets assigned the object’s key.
value_var: Identifier
The name of the variable that will be temporarily assigned the value of each element during iteration.
collection_expr: Expression
An expression that must evaluate to a value that can be iterated.
key_expr: Option<Expression>
An expression that is evaluated once for each key in the source collection. If set, the
result of the for
expression will be an object. Otherwise, the result will be an array.
value_expr: Expression
An expression that is evaluated once for each value in the source collection.
grouping: bool
Indicates whether grouping mode is enabled. In grouping mode, each value in the resulting
object is a list of all of the values that were produced against each distinct key. This is
ignored if key_expr
is None
.
cond_expr: Option<Expression>
An optional filter expression. Elements for which the condition evaluates to true
will
be evaluated as normal, while if false
the element will be skipped.
Implementations§
Source§impl ForExpr
impl ForExpr
Sourcepub fn new<C, V>(
value_var: Identifier,
collection_expr: C,
value_expr: V,
) -> ForExpr
pub fn new<C, V>( value_var: Identifier, collection_expr: C, value_expr: V, ) -> ForExpr
Create a new ForExpr
with the name of the variable that will be temporarily assigned the
value of each element during iteration, an expression that must evaluate to a value that
can be iterated, and one expression that is evaluated once for each value in the source
collection.
Sourcepub fn with_key_var(self, key_var: Identifier) -> ForExpr
pub fn with_key_var(self, key_var: Identifier) -> ForExpr
Adds the iterator key variable identifier to the for
expression and returns the modified
ForExpr
.
Sourcepub fn with_key_expr<T>(self, key_expr: T) -> ForExprwhere
T: Into<Expression>,
pub fn with_key_expr<T>(self, key_expr: T) -> ForExprwhere
T: Into<Expression>,
Adds an expression that is evaluated once for each key in the source collection. If set,
the result of the for
expression will be an object. Returns the modified ForExpr
.
Sourcepub fn with_cond_expr<T>(self, cond_expr: T) -> ForExprwhere
T: Into<Expression>,
pub fn with_cond_expr<T>(self, cond_expr: T) -> ForExprwhere
T: Into<Expression>,
Sets the filter expression. Elements for which the condition evaluates to true
will be
evaluated as normal, while if false
the element will be skipped.
Sourcepub fn with_grouping(self, yes: bool) -> ForExpr
pub fn with_grouping(self, yes: bool) -> ForExpr
Enables or disabled grouping mode.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for ForExpr
impl<'de> Deserialize<'de> for ForExpr
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl Evaluate for ForExpr
impl Evaluate for ForExpr
Source§fn evaluate(&self, ctx: &Context<'_>) -> EvalResult<Self::Output>
fn evaluate(&self, ctx: &Context<'_>) -> EvalResult<Self::Output>
Context
. Read moreSource§fn evaluate_in_place(&mut self, ctx: &Context<'_>) -> EvalResult<(), Errors>
fn evaluate_in_place(&mut self, ctx: &Context<'_>) -> EvalResult<(), Errors>
Source§impl Format for ForExpr
impl Format for ForExpr
Source§fn format<W>(&self, fmt: &mut Formatter<'_, W>) -> Result<()>where
W: Write,
fn format<W>(&self, fmt: &mut Formatter<'_, W>) -> Result<()>where
W: Write,
Source§impl From<ForExpr> for Expression
impl From<ForExpr> for Expression
Source§impl<'de> IntoDeserializer<'de, Error> for ForExpr
impl<'de> IntoDeserializer<'de, Error> for ForExpr
Source§type Deserializer = MapAccessDeserializer<ForExprAccess>
type Deserializer = MapAccessDeserializer<ForExprAccess>
Source§fn into_deserializer(self) -> Self::Deserializer
fn into_deserializer(self) -> Self::Deserializer
impl Eq for ForExpr
impl StructuralPartialEq for ForExpr
Auto Trait Implementations§
impl Freeze for ForExpr
impl RefUnwindSafe for ForExpr
impl Send for ForExpr
impl Sync for ForExpr
impl Unpin for ForExpr
impl UnwindSafe for ForExpr
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.