code copied verbatim from the rust Pin documentation https://doc.rust-lang.org/std/pin/macro.pin.html#with-generators. what does static
preceding the ||
mean?
fn generator_fn() -> impl Generator<Yield = usize, Return = ()> /* not Unpin */ {
// Allow generator to be self-referential (not `Unpin`)
// vvvvvv so that locals can cross yield points.
static || {
let foo = String::from("foo");
let foo_ref = &foo; // ------+
yield 0; // | <- crosses yield point!
println!("{foo_ref}"); // <--+
yield foo.len();
}
}