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: IdentifierThe name of the variable that will be temporarily assigned the value of each element during iteration.
collection_expr: ExpressionAn 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: ExpressionAn expression that is evaluated once for each value in the source collection.
grouping: boolIndicates 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
) -> ForExprwhere
C: Into<Expression>,
V: Into<Expression>,
pub fn new<C, V>(
value_var: Identifier,
collection_expr: C,
value_expr: V
) -> ForExprwhere
C: Into<Expression>,
V: Into<Expression>,
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 From<ForExpr> for Expression
impl From<ForExpr> for Expression
source§impl<'de> IntoDeserializer<'de, Error> for ForExpr
impl<'de> IntoDeserializer<'de, Error> for ForExpr
§type Deserializer = MapAccessDeserializer<ForExprAccess>
type Deserializer = MapAccessDeserializer<ForExprAccess>
source§fn into_deserializer(self) -> Self::Deserializer
fn into_deserializer(self) -> Self::Deserializer
source§impl PartialEq<ForExpr> for ForExpr
impl PartialEq<ForExpr> for ForExpr
impl Eq for ForExpr
impl StructuralEq for ForExpr
impl StructuralPartialEq for ForExpr
Auto Trait Implementations§
impl RefUnwindSafe for ForExpr
impl Send for ForExpr
impl Sync for ForExpr
impl Unpin for ForExpr
impl UnwindSafe for ForExpr
Blanket Implementations§
source§impl<Q, K> Equivalent<K> for Qwhere
Q: Eq + ?Sized,
K: Borrow<Q> + ?Sized,
impl<Q, K> Equivalent<K> for Qwhere
Q: Eq + ?Sized,
K: Borrow<Q> + ?Sized,
source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.