Closures get compiled down to anonymous structs which include their captures as the struct's fields.
That means a capturing closure
let x = 1i32;
let c = || println!("{x}");
c();Is compiled to[^1]
| #![feature(gen_blocks)] | |
| fn foo() -> impl Iterator<Item = i32> { | |
| gen { | |
| yield 123; | |
| for i in 0..10 { | |
| yield i * i; | |
| } | |
| yield 321; | |
| } |
| [package] | |
| name = "foo" | |
| version = "0.1.0" | |
| edition = "2021" | |
| # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | |
| [dependencies] | |
| [dependencies.windows] |
| [dependencies] | |
| thiserror = "1.0.30" | |
| [dependencies.windows] | |
| version = "0.33.0" | |
| features = [ | |
| "Win32_System_Threading", | |
| "Win32_Foundation", | |
| "Win32_Security", | |
| "Win32_System_SystemServices" |