Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Manually type the outputs of a generator using gen! #26

Open
philip-peterson opened this issue Jul 6, 2020 · 0 comments
Open

Manually type the outputs of a generator using gen! #26

philip-peterson opened this issue Jul 6, 2020 · 0 comments

Comments

@philip-peterson
Copy link

Hi there,

I am wanting to have a generator that will yield values that are an Rc<dyn T>. Currently I have to do it like so:

async fn produce_pages(mut co: Co<'_, Rc<dyn GeneratedPage>>) {
    co.yield_(Rc::new(HomePage {})).await;
    co.yield_(Rc::new(ContactPage {})).await;
}

fn foo() -> () {
    let_gen_using!(gen_all_pages, produce);
    gen_all_pages.into_iter().collect();
}

This means that foo cannot return the iterator sadly because of the use of let_gen_using, which leaks the shelf value which is owned by the foo function.

The whole reason I need to use the producer pattern is because gen!() doesn't accept a type argument (which is needed because of the dyn); would it be possible to have it allow a field that specifies what type the Rust compiler should know the generator results to be?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant