lifetime/
lifetime.rs

1fn main() {
2    let str = "foo".to_string();
3
4    let mut gen = generator::Gn::new_scoped(|mut s| {
5        std::thread::scope(|s2| {
6            s2.spawn(|| {
7                std::thread::sleep(std::time::Duration::from_millis(500));
8                println!("{str}");
9            });
10            // here we can't use `yield_` because it still ref to `str`
11            // `yield_` only impl for static captured lifetime
12            // s.yield_(());
13            unsafe { s.yield_unsafe(()) };
14        });
15        generator::done!();
16    });
17
18    gen.next();
19    // std::mem::forget(gen);
20    // drop(gen);
21    // drop(str);
22    std::thread::sleep(std::time::Duration::from_millis(1000));
23}