pub struct LoopScope<R>(_);
Expand description
A special kind of Scope
that can also break loops.
Implementations
sourceimpl<R> LoopScope<R> where
Return: From<R>,
impl<R> LoopScope<R> where
Return: From<R>,
sourcepub fn loop_continue(&mut self)
pub fn loop_continue(&mut self)
Break the current iteration of the nearest loop and continue to the next iteration.
sourcepub fn loop_break(&mut self)
pub fn loop_break(&mut self)
Break the nearest loop.
Methods from Deref<Target = Scope<R>>
sourcepub fn var<T>(&mut self, init_value: Expr<T>) -> Var<T> where
T: ToType,
pub fn var<T>(&mut self, init_value: Expr<T>) -> Var<T> where
T: ToType,
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.
sourcepub fn loop_for<T>(
&mut self,
init_value: Expr<T>,
condition: impl FnOnce(&Expr<T>) -> Expr<bool>,
iter_fold: impl FnOnce(&Expr<T>) -> Expr<T>,
body: impl FnOnce(&mut LoopScope<R>, &Expr<T>)
) where
T: ToType,
pub fn loop_for<T>(
&mut self,
init_value: Expr<T>,
condition: impl FnOnce(&Expr<T>) -> Expr<bool>,
iter_fold: impl FnOnce(&Expr<T>) -> Expr<T>,
body: impl FnOnce(&mut LoopScope<R>, &Expr<T>)
) where
T: ToType,
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.
sourcepub fn loop_while(
&mut self,
condition: impl Into<Expr<bool>>,
body: impl FnOnce(&mut LoopScope<R>)
)
pub fn loop_while(
&mut self,
condition: impl Into<Expr<bool>>,
body: impl FnOnce(&mut LoopScope<R>)
)
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.
Trait Implementations
sourceimpl<R> Erased for LoopScope<R>
impl<R> Erased for LoopScope<R>
type Erased = ErasedScope
type Erased = ErasedScope
Erased version.
sourcefn erased_mut(&mut self) -> &mut Self::Erased
fn erased_mut(&mut self) -> &mut Self::Erased
Mutable access to the erased version.
Auto Trait Implementations
impl<R> RefUnwindSafe for LoopScope<R> where
R: RefUnwindSafe,
impl<R> Send for LoopScope<R> where
R: Send,
impl<R> Sync for LoopScope<R> where
R: Sync,
impl<R> Unpin for LoopScope<R> where
R: Unpin,
impl<R> UnwindSafe for LoopScope<R> where
R: UnwindSafe,
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more