Skip to main content


You can add the __copy_capture decorator on a parametric closure to capture register-passable values by copy. This decorator causes a nested function to copy the value of the indicated variable into the closure object at the point of formation instead of capturing that variable by reference. This allows the closure to be passed as an escaping function, without lifetime concerns.

  fn foo(x: Int):
var z = x

fn formatter() -> Int:
return z
z = 2

fn main():