1

Is there a way to have closures call themselves recursively, e.g.:

fn main() {
    let recurse = |x: i32| { 
        println!("{}", x);
        let x_next = x + 1;
        if x < 10 {
            recurse(x_next);  // commenting this line will build
        }
        x_next;
    };

    recurse(1);
}

Is there a way to workaround the closure not being defined in the closure body?

Shepmaster
  • 388,571
  • 95
  • 1,107
  • 1,366
ideasman42
  • 42,413
  • 44
  • 197
  • 320

0 Answers0