Skip to content

Instantly share code, notes, and snippets.

@linkdd
Created May 11, 2022 09:29
Show Gist options
  • Save linkdd/48c3be67a1e283d1a7909e110e0a3771 to your computer and use it in GitHub Desktop.
Save linkdd/48c3be67a1e283d1a7909e110e0a3771 to your computer and use it in GitHub Desktop.
Return Rust generator from function
use genawaiter::{sync::gen, yield_, Generator};
type MyGen = Box<dyn Generator<Yield = i32, Return = i32>>;
fn make_generator() -> MyGen {
let gen = gen!({
yield_!(1);
yield_!(2);
yield_!(3);
4
});
Box::new(gen)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment