Loops with returns regeneration


#1

This idea is useful and harmonize with expression based foundation of Rust:



I’ve found a simple alternative approach to return values outside the loop:

fn main() {
    let loop_result = (move || loop {
        return 32i32;
    })();
    println!("{:?}", loop_result);
}

Sounds like moved loop :grinning: (it’s not necessary in this case). Also I can use try! macro with this approach.

How much overhead such loops wrapping has?
Maybe are there alternative ways to have a infinite loop which runs a long sequence that can be broken anytime with Err which I want to use for silently error processing (without panic)?