@@ -195,13 +195,51 @@ pub mod expr {
195195 /// messages `has(m.x)` is defined as 'defined, but not set`. For proto3, the
196196 /// macro tests whether the property is set to its default. For map and struct
197197 /// types, the macro tests whether the property `x` is defined on `m`.
198+ ///
199+ /// Comprehensions for the standard environment macros evaluation can be best
200+ /// visualized as the following pseudocode:
201+ ///
202+ /// ```
203+ /// let `accu_var` = `accu_init`
204+ /// for (let `iter_var` in `iter_range`) {
205+ /// if (!`loop_condition`) {
206+ /// break
207+ /// }
208+ /// `accu_var` = `loop_step`
209+ /// }
210+ /// return `result`
211+ /// ```
212+ ///
213+ /// Comprehensions for the optional V2 macros which support map-to-map
214+ /// translation differ slightly from the standard environment macros in that
215+ /// they expose both the key or index in addition to the value for each list
216+ /// or map entry:
217+ ///
218+ /// ```
219+ /// let `accu_var` = `accu_init`
220+ /// for (let `iter_var`, `iter_var2` in `iter_range`) {
221+ /// if (!`loop_condition`) {
222+ /// break
223+ /// }
224+ /// `accu_var` = `loop_step`
225+ /// }
226+ /// return `result`
227+ /// ```
198228 #[ allow( clippy:: derive_partial_eq_without_eq) ]
199229#[ derive( Clone , PartialEq , :: prost:: Message ) ]
200230 pub struct Comprehension {
201- /// The name of the iteration variable.
231+ /// The name of the first iteration variable.
232+ /// When the iter_range is a list, this variable is the list element.
233+ /// When the iter_range is a map, this variable is the map entry key.
202234 #[ prost( string, tag="1" ) ]
203235 pub iter_var : :: prost:: alloc:: string:: String ,
204- /// The range over which var iterates.
236+ /// The name of the second iteration variable, empty if not set.
237+ /// When the iter_range is a list, this variable is the integer index.
238+ /// When the iter_range is a map, this variable is the map entry value.
239+ /// This field is only set for comprehension v2 macros.
240+ #[ prost( string, tag="8" ) ]
241+ pub iter_var2 : :: prost:: alloc:: string:: String ,
242+ /// The range over which the comprehension iterates.
205243 #[ prost( message, optional, boxed, tag="2" ) ]
206244 pub iter_range : :: core:: option:: Option < :: prost:: alloc:: boxed:: Box < super :: Expr > > ,
207245 /// The name of the variable used for accumulation of the result.
@@ -210,13 +248,13 @@ pub mod expr {
210248 /// The initial value of the accumulator.
211249 #[ prost( message, optional, boxed, tag="4" ) ]
212250 pub accu_init : :: core:: option:: Option < :: prost:: alloc:: boxed:: Box < super :: Expr > > ,
213- /// An expression which can contain iter_var and accu_var.
251+ /// An expression which can contain iter_var, iter_var2, and accu_var.
214252 ///
215253 /// Returns false when the result has been computed and may be used as
216254 /// a hint to short-circuit the remainder of the comprehension.
217255 #[ prost( message, optional, boxed, tag="5" ) ]
218256 pub loop_condition : :: core:: option:: Option < :: prost:: alloc:: boxed:: Box < super :: Expr > > ,
219- /// An expression which can contain iter_var and accu_var.
257+ /// An expression which can contain iter_var, iter_var2, and accu_var.
220258 ///
221259 /// Computes the next value of accu_var.
222260 #[ prost( message, optional, boxed, tag="6" ) ]
0 commit comments