pub struct LoopScope<R>(_);
Expand description

A special kind of Scope that can also break loops.

Implementations

Break the current iteration of the nearest loop and continue to the next iteration.

Break the nearest loop.

Methods from Deref<Target = Scope<R>>

Bind an expression to a variable in the current scope.

let v = s.var(e); binds the e expression to v in the s Scope<T>, and e must have type Expr<T> and v must be a Var<T>, with T: ToType.

Return

The resulting Var<T> contains the representation of the binding in the EDSL and the actual binding is recorded in the current scope.

For looping statement — for.

s.loop_for(i, |i| /* cond */, |i| /* fold */, |i| /* body */ ) inserts a looping statement into the EDSL representing a typical “for” loop. i is an Expr<T> satisfying T: ToType and is used as initial value.

In all the following closures, i refers to the initial value.

The first cond closure must return an Expr<bool>, representing the condition that is held until the loop exits. The second fold closure is a pure computation that must return an Expr<T> and that will be evaluated at the end of each iteration before the next check on cond. The last and third body closure is the body of the loop.

The behaviors of the first two closures is important to understand. Those are akin to filtering and folding. The closure returning the Expr<bool> is given the Expr<T> at each iteration and the second closure creates the new Expr<T> for the next iteration. Normally, people are used to write this pattern as i++, for instance, but in the case of our EDSL, it is more akin go i + 1, and this value is affected to a local accumulator hidden from the user.

The LoopScope<R> argument to the body closure is a specialization of Scope<R> that allows breaking out of loops.

While looping statement — while.

s.loop_while(cond, body) inserts a looping statement into the EDSL representing a typical “while” loop.

cond is an Expr<bool>, representing the condition that is held until the loop exits. body is the content the loop will execute at each iteration.

The LoopScope<R> argument to the body closure is a specialization of Scope<R> that allows breaking out of loops.

Mutate a variable in the current scope.

Early-return the current function with an expression.

Early-abort the current function.

Trait Implementations

Formats the value using the given formatter. Read more

Create a new fresh scope under the current scope.

The resulting type after dereferencing.

Dereferences the value.

Mutably dereferences the value.

Erased version.

Consumer the typed interface and return the erased version.

Immutable access to the erased version.

Mutable access to the erased version.

Converts to this type from the input type.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Conditional statement — if. Read more

Complement form of [Scope::when]. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.